Selenium maven 运行不了 testng.xml 怎么回事

Tony · March 27, 2018 · Last by 对酒当歌 replied at September 14, 2018 · 3965 hits

maven的pom.xml是这样的

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>demo</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suitexmlfiles>
<suitexmlfile>testng.xml</suitexmlfile>
</suitexmlfiles>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

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="demo.Sample"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

然而我运行mvn test的时候什么都没有运行,好像是maven没有找到testng.xml, 实在不清楚怎么回事,求解答

共收到 7 条回复 时间 点赞
<!--添加插件 关联testNg.xml-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<!-- 有疑问 ,加上这段代码就没有多余的report文件了-->
<!-- 添加插件,添加ReportNg的监听器,生成TestNg的报告 -->
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter</value>
</property>
</properties>
<testFailureIgnore>false</testFailureIgnore>
<suiteXmlFiles>/
<!--<file>${project.basedir}/target/classes/testNGJunit.xml</file>-->
<file>${project.basedir}/target/classes/testNG.xml</file>
</suiteXmlFiles>
<workingDirectory>target/</workingDirectory>
</configuration>
</plugin>
Tony #2 · April 04, 2018 作者
oly 回复

试过了还是不管用

maven只识别以Test,或者TestCase结尾的java文件,试试看

maven surefire

楼主这个问题解决了么??

遇到同样的问题,楼主求解

默默 回复

解决了没

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up