ռ λ: 51Testing » ΪУ » ־

TestNGѧϰ֮·HelloWorld

һƪ / һƪ  2019-04-26 09:43:24 / ˷ࣺ

       ǰ
ƪҪǻátestNGšִݡ
IntelliJ IDEA
TestNG 6.11
Maven
pom.xml
½һmavenĿpom.xml
   <?xml version="1.0" encoding="UTF-8"?>
<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>TestNG-Learning</groupId>
<artifactId>TestNG</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
</dependencies>
</project>
TestNG쳣򵥣ʾ@BeforeClassעⷽ൱ִǰ׼@Testעⷽ൱ִУ@AfterClassעⷽ൱ִк/ָעٸǽ⡣
   import org.testng.annotations.*;
public class TestNGHelloWorld {
@BeforeClass
public void setUp(){
System.out.println("setUp!");
}
@Test
public void helloWorld(){
System.out.println("My first TestNG testCase!");
}
@AfterClass
public void tearDown(){
System.out.println("tearDown!");
}
}
   ִн£
   setUp!
My first TestNG testCase!
tearDown!
===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
ִв
дɺ󣬿ͨ¼ַʽִвԡ
ant
ʹantִвԣѭ¡
1װant
2build.xmlļ
   <project default="test">
<path id="cp">
<pathelement location="lib/testng-6.11.jar"/>
<pathelement location="lib/jcommander-1.48.jar"/>
<pathelement location="build"/>
</path>
<taskdef name="testng" classpathref="cp"
classname="org.testng.TestNGAntTask" />
<target name="test">
<testng classpathref="cp" >
<classfileset dir="build" includes="TestNGHelloWorld.class"/>
</testng>
</target>
</project>
3лbuild.xmlļĿ¼ִant
   D:\IntelliJ_IDEA_workspace\TestNG>ant
Buildfile: D:\IntelliJ_IDEA_workspace\TestNG\build.xml
test:
[testng] setUp!
[testng] My first TestNG testCase!
[testng] tearDown!
[testng]
[testng] ===============================================
[testng] Ant suite
[testng] Total tests run: 1, Failures: 0, Skips: 0
[testng] ===============================================
[testng]
BUILD SUCCESSFUL
Total time: 2 seconds
Ŀ¼ṹʾ
ļṹ-ant
TestNGHelloWorld.class
lib
jcommander.jar򱨴¡
   D:\IntelliJ_IDEA_workspace\TestNG>ant
Buildfile: D:\IntelliJ_IDEA_workspace\TestNG\build.xml
test:
[testng] java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
[testng]     at java.lang.Class.getDeclaredMethods0(Native Method)
[testng]     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
[testng]     at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
[testng]     at java.lang.Class.getMethod0(Class.java:3018)
[testng]     at java.lang.Class.getMethod(Class.java:1784)
[testng]     at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
[testng]     at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
[testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
[testng]     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[testng]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[testng]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[testng]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[testng]     ... 7 more
[testng] Error: A JNI error has occurred, please check your installation and try again
[testng] The tests failed.
а·Ѱ·ȥ
   <project default="test">
<path id="cp">
<pathelement location="lib/testng-6.8.7.jar"/>
<pathelement location="lib/jcommander-1.48.jar"/>
<pathelement location="build"/>
</path>
<taskdef name="testng" classpathref="cp"
classname="org.testng.TestNGAntTask" />
<target name="test">
<testng classpathref="cp" >
<!--includesϰ·-->
<classfileset dir="build" includes="com/demo/test/TestHello.class"/>
</testng>
</target>
</project>
xmlִ
½testNG.xmlļ(ɲοIDEAԶTestNGtestng.xml)ҼrunɡxmlṹǸclassִвԣṹú⡣
   <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
<test name="TestNG">
<classes>
<class name="TestNGHelloWorld"/>
</classes>
</test> <!-- TestNG -->
</suite> <!-- Default Suite -->
testNG.xml run
   ִ
1
TestNGHome
ClassPath
2
TestNGHelloWorld.class
3Զclasspath2TestNGHelloWorld.class·
 java -classpath "%classpath%;D:\IntelliJ_IDEA_workspace\TestNG\build" org.testng.TestNG testNG.xml
ִxml
   D:\IntelliJ_IDEA_workspace\TestNG\lib>java -classpath "%classpath%;D:\IntelliJ_IDEA_workspace\TestNG\build" org.testng.TestNG testNG.xml
[TestNG] Running:
D:\IntelliJ_IDEA_workspace\TestNG\lib\testNG.xml
setUp!
My first TestNG testCase!
tearDown!
===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
ִclass
   D:\IntelliJ_IDEA_workspace\TestNG\lib>java -classpath "%classpath%;D:\IntelliJ_IDEA_workspace\TestNG\build" org.testng.TestNG -testclass TestNGHelloWorld
[TestNG] Running:
Command line suite
setUp!
My first TestNG testCase!
tearDown!
===============================================
Command line suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
ԽпطıļУd:\test.txtTestNGʹøļִнһ¡
d:\test.txt ݣtestNG.xml
classļD:\IntelliJ_IDEA_workspace\TestNG\lib
   D:\IntelliJ_IDEA_workspace\TestNG\lib>java -Dtestng.test.classpath org.testng.TestNG @d:\test.txt
[TestNG] Running:
D:\IntelliJ_IDEA_workspace\TestNG\lib\testNG.xml
setUp!
My first TestNG testCase!
tearDown!
===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 0
ִиIJɲο
 ݲҵĿģ漰֪ʶȨ⣬ȨϵΪС(021-64471599-8052)ǽ
 

 
 
 
 
   
˽γݼγ̰ţѯQQ 2852509883 µͷ 400-821-09519:00-17:30


TAG:

 

֣0

˵

ʾȫ

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar