背景:
本地編寫的很多testNG測試用例,可能需要對接其他人員,運用其他形式執行,例如將測試用例達成jar包,由運維執行,需要提供執行命令,提供前需要本地先驗證是否可執行通過。
一、maven配置
1.官網下載maven(https://maven.apache.org/download.cgi),下載最新版本,解壓到制定文件夾:
2.配置環境變量,以win10為例:
新建系統變量MAVEN_HOME,填寫下載解壓后的文件地址,注意是bin目錄的上一級目錄
編輯Path變量,在末尾加上:
3.檢驗,cmd,進入終端,輸入mvn -v ,顯示以下信息說明配置完成
二、Idea執行配置【注意配置好maven/jdk環境(JDK下載參照以前教程)變量后需要重啟idea】
1.在pom.xml引入依賴:
- <build>
- <sourceDirectory>src/main/java</sourceDirectory>
- <testSourceDirectory>src/main/java</testSourceDirectory>
- <finalName>${project.artifactId}</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>7</source>
- <target>7</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.6</version>
- <!--jar-->
- <configuration>
- <argLine>
- -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar"
- </argLine>
- <testFailureIgnore>true</testFailureIgnore>
- <!-- <testNGArtifactName>org.testng:testng</testNGArtifactName>-->
- <forkMode>once</forkMode>
- <!--<skipTests>true</skipTests>-->
- <skipTests>false</skipTests>
- <suiteXmlFiles>
- <suiteXmlFile>suites/test.xml</suiteXmlFile>
- </suiteXmlFiles>
- <properties>
- <property>
- <name>usedefaultlisteners</name>
- <value>false</value>
- </property>
- <property>
- <name>listener</name>
- <value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>
- </property>
- </properties>
- <forkMode>always</forkMode>
- </configuration>
- <!--jar-->
- <dependencies>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjweaver</artifactId>
- <version>1.8.10</version>
- </dependency>
- </dependencies>
- </plugin>
- <!--jar-->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>3.0.0</version>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- <mainClass>com.uiautotest.platformsys.JavaRunXml</mainClass>
- </manifest>
- </archive>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>3.0.0</version>
- <configuration>
- <!-- put your configurations here -->
- <transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <manifestEntries>
- <Main-Class>org.testng.TestNG</Main-Class>
- </manifestEntries>
- </transformer>
- </transformers>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
2.在Terminal執行:mvn clean test -Dsurefire.suiteXmlFiles=suites/test.xml,即可執行成功。 或者直接執行 mvn test【執行的suites/test.xml已經通過上述的pom.xml配置過了,所以可以直接執行】
3.執行命令其實來源于maven helper依賴:
到此這篇關于testNG項目通過idea Terminal命令行執行的文章就介紹到這了,更多相關idea Terminal命令行執行內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://www.cnblogs.com/jiangger/p/15011079.html