Запуск Junit в командной строке - PullRequest
0 голосов
/ 06 февраля 2019

initializationError(org.junit.runner.JUnitCommandLineParseResult) появляется ошибка, когда jUnit код запускается в командной строке Windows:

Z: \ lib \ com \ example \ tests> java -cp Z: \ lib \ junit-4.12.jar; Z: \ lib \ hamcrest-core-1.3.jar org.junit.runner.JUnitCore TripPlannerJunit JUnit версия 4.12.E Время: 0 Произошел 1 сбой: 1) initializationError (org.junit.runner.JUnitCommandLineParseResult) java..IllegalArgumentException: не удалось найти класс [TripPlannerJunit] по адресу org.junit.runner.JUnitCommandLineParseResult.parseParameters (JUnitCommandLineParseResult.java:102) по адресу org.junit.runner.jesse.it.JUnitCommandLineParseResult.parse (JUnitCommandLineParseResult.java:44) в org.junit.runner.JUnitCore.runMain (JUnitCore.java:72) в org.junit.runner.JUnitava.Core: JC:.lang.ClassNotFoundException: TripPlannerJunitat java.base / jdk.internal.loader.BuiltinClassLoader.loadClass (BuiltinClassLoader.java:583) в java.base / jdk.internal.loader.ClassLoaders $ AppClassLoader.loadClass (ClassLoaders.java:178) в java.base / java.lang.ClassLoader.loadClass (ClassLoader.java:521) в java.base / java.lang.Class.forName0 (собственный метод) в java.base / java.lang.Class.forName (Class.java:398) в org.junit.internal.Classes.getClass (Classes.java:16) в org.junit.runner.JUnitCommandLineParseResult.parseParameters (JUnitCommandLinePjseRes):... еще 4 НЕУДАЧИ !!!Выполнено тестов: 1, сбоев: 1 отредактировано -.Структура выглядит следующим образом: все банки находятся в "Z: \ TripPlanner \ lib".Класс и java файлы находятся в - "Z: \ TripPlanner \ lib \ com \ example \ tests". Объявлен пакет com.example.tests

package com.example.tests;
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import io.github.bonigarcia.wdm.ChromeDriverManager;

public class TripPlannerJUnit {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    ChromeDriverManager.getInstance().setup();
    driver = new ChromeDriver();
    baseUrl = "https://www.google.com.au/.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testUntitledTestCase() throws Exception {
    driver.get("https://transportnsw.info/trip#/");
    driver.findElement(By.id("search-input-From")).click();
    driver.findElement(By.id("search-input-From")).clear();
    driver.findElement(By.id("search-input-From")).sendKeys("North");
    driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='North Sydney Station'])[1]/following::li[1]")).click();
    driver.findElement(By.id("search-input-To")).click();
    driver.findElement(By.id("search-input-To")).clear();
    driver.findElement(By.id("search-input-To")).sendKeys("Town");
    driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='Town Hall Station'])[1]/following::ul[1]")).click();
    driver.findElement(By.id("search-button")).click();
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }
  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}

1 Ответ

0 голосов
/ 06 февраля 2019

Пожалуйста, укажите путь к вашему TripPlannerJunit.

Если это текущая папка проекта:

java -cp .;Z:\lib\junit-4.12.jar;...

или

java -cp %CD%;Z:\lib\junit-4.12.jar;...

ОБНОВЛЕНИЕ на основе разъяснений в комментариях.

Предполагается, что у вас есть такая структура:

Z:\TripPlanner\lib\
|   hamcrest-core-1.3.jar
|   junit-4.12.jar
|
+---com
|   \---example
|       \---tests
|               TripPlannerJunit.java
|               TripPlannerJunit.class

Запустите тест из папки Z:\TripPlanner\lib:

Z:\TripPlanner\lib>java -cp .;junit-4.12.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore "com.example.tests.TripPlannerJunit"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...