我有Maven项目,并且所有配置都是正确的,最近我用GIT和Jenkins配置了项目,创建了Jenkin作业。
之前,我能够运行完整的项目 右键单击项目并运行**-> **运行-> Maven测试,然后使用测试执行来启动,但现在它不会引发任何错误,但不会启动浏览器执行。
但是,如果我使用TestNG分别运行Java文件[单个测试用例],则其工作将按预期进行[启动浏览器并开始执行]
正如我使用Jenkins配置的那样,我无法单独运行每个测试用例。 我将必须使用 Maven测试
来运行该项目我已经尝试了可能的解决方案:
请在 pom.xml
中找到我使用的代码段
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</build>
提前感谢所有建议:)
答案 0 :(得分:1)
要追踪原因,您可以按照以下步骤进行操作。您会发现真正的原因在哪里,它会被卡住。
1。使用控制台输出创建简单的@Test:
public class NewTest {
@Test
public void f() {
System.out.println("Hello World");
}
}
2。在项目的根位置创建TestNG.XML以执行上述类:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="packageName.NewTest"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
3。运行并检查TESTNG.XML输出
4。运行并检查POM.XML的输出
POM.XML:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
答案 1 :(得分:0)
<test name="sample-Test" preserve-order="true" verbose="2">
<packages>
<package name="org.sample.something.*"/>
</packages>
</test>
2.1更新您的surefire插件配置以使其:
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
2.2 OR(更灵活,因为您可以创建指向不同xml的不同配置文件以分别运行不同的测试套件)创建一个将指向您的testNG xml的maven配置文件
<profiles>
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
mvn clean test -U -Pselenium-tests
或mvn clean test