2

我正在尝试使用 JUNIT 4.10 和 Selenium 为在 Eclipse 中使用 Maven 的 Web 应用程序运行测试用例。

我创建了一个简单的 java 项目,其中 JUNIT 测试用例添加了适当的依赖项。它工作得很好,Run as a JUNIT Test case但它不能作为 Maven 测试工作,所以类似mvn clean test的东西不起作用。

这是我对 pom.xml 的摘录

    <build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
    </plugin>
</plugins>

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.10</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi</artifactId>
  <version>3.8</version>
  <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.25.0</version>
    <type>jar</type>
    <scope>test</scope>
</dependency>

这也是我写的 JUnit 测试用例,

@Test()
public void testTC101() throws InterruptedException{
    driver.get(ADMIN_BASE_URL_QA);
    driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//*[@id='top30Events']"));
    WebElement loanModFullEvent = driver.findElement(By.partialLinkText(QA_MOD_FULL_EVENT));
    loanModFullEvent.click();
    String clickedFullEventId = loanModFullEvent.findElement(By.xpath("..")).getAttribute("id").split("_")[1];
    List<WebElement> nearbyEvents = driver.findElements(By.id("nearby_events_" + clickedFullEventId));
    ListIterator<WebElement> wIterator = nearbyEvents.listIterator();
    WebElement element = null;
    String registerNowId = null;
    while(wIterator.hasNext()) {
        element = wIterator.next().findElement(By.linkText(QA_MOD_NONFULL_EVENT));
        element.click();
        registerNowId = element.getAttribute("onclick").replaceAll("\\D+", "");
    }
    registerNowId = "top30_" + registerNowId;
    driver.findElement(By.xpath("//*[@id='" + registerNowId + "']/div[3]/div/a")).click();              
    WebElement dropDownListBox = driver.findElement(By.xpath("//*[@id='list']"));
    Select clickThis = new Select(dropDownListBox);
    clickThis.selectByValue("mod");
    driver.findElement(By.xpath("//*[@id='situationdropdown']/div/div/div[1]/span/span/span/input")).click();
    RegistrationForm.fillFormAndSubmit();

}

代码只是为了这个想法,但问题是它在 JUnit 测试用例中运行,为什么不使用 maven。它说测试:0 次运行:0 次跳过:0

为什么它不识别测试,我仍然不确定为什么?有人可以帮忙吗?

4

1 回答 1

2

您说您的测试类名称以 Tests 结尾。根据surefire插件站点,这不是默认模式之一:http ://maven.apache.org/plugins/maven-surefire-plugin/examples/inclusion-exclusion.html

**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test
**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test
**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase
于 2012-11-08T20:50:27.273 回答