testng.org

http://testng.org/doc/index.html

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use, such as:

  • Annotations.
  • Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc...).
  • Test that your code is multithread safe.
  • Flexible test configuration.
  • Support for data-driven testing (with @DataProvider).
  • Support for parameters.
  • Powerful execution model (no more TestSuite).
  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).
  • Embeds BeanShell for further flexibility.
  • Default JDK functions for runtime and logging (no dependencies).
  • Dependent methods for application server testing.

TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc...

I started TestNG out of frustration for some JUnit deficiencies which I have documented on my weblog here and here Reading these entries might give you a better idea of the goal I am trying to achieve with TestNG. You can also check out a quick overview of the main features and an article describing a very concrete example where the combined use of several TestNG's features provides for a very intuitive and maintainable testing design.

Here is a very simple test:

SimpleTest.java

package example1;
import org.testng.annotations.*;
public class SimpleTest {
@BeforeClass
public void setUp() {
// code that will be invoked when this test is instantiated
}
@Test(groups = { "fast" })
public void aFastTest() {
System.out.println("Fast test");
}
@Test(groups = { "slow" })
public void aSlowTest() {
System.out.println("Slow test");
}
}

The method setUp() will be invoked after the test class has been built and before any test method is run. In this example, we will be running the group fast, so aFastTest() will be invoked while aSlowTest() will be skipped.

Things to note:

  • No need to extend a class or implement an interface.
  • Even though the example above uses the JUnit conventions, our methods can be called any name you like, it's the annotations that tell TestNG what they are.
  • A test method can belong to one or several groups.

Once you have compiled your test class into the build directory, you can invoke your test with the command line, an ant task (shown below) or an XML file:

build.xml

<project default="test">
<path id="cp">
<pathelement location="lib/testng-testng-5.13.1.jar"/>
<pathelement location="build"/>
</path>
<taskdef name="testng" classpathref="cp"
classname="org.testng.TestNGAntTask" />
<target name="test">
<testng classpathref="cp" groups="fast">
<classfileset dir="build" includes="example1/*.class"/>
</testng>
</target>
</project>

Use ant to invoke it:

c:> ant
Buildfile: build.xml
test:
[testng] Fast test
[testng] ===============================================
[testng] Suite for Command line test
[testng] Total tests run: 1, Failures: 0, Skips: 0
[testng] ===============================================
BUILD SUCCESSFUL
Total time: 4 seconds

Then you can browse the result of your tests:

start test-output\index.html (on Windows)

Requirements

TestNG requires JDK 5 or higher.

Mailing-lists

Locations of the projects

If you are interested in contributing to TestNG or one of the IDE plug-ins, you will find them in the following locations:

TestNG是一个Java的框架,所以第一个要求是JDK要安装在你的机器上。 系统要求 JDK 1.5或以上 内存 没有最低要求 磁盘空间 没有最低要求 操作系统 没有最低要求 步骤1 -验证Java安装在你的机器上 现在,打开控制台并执行以下的java命令。 OS 任务 命令 Windows 打开命令控制台 c:\> java -version Linux 打开命令终端 $ java -version Mac 打开命令终端 machine:~ joseph$ java -version 让我们来验证所有的操作系统的输出: OS 输出 Windows java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) Linux java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) Mac java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) 如果你没有安装Java,安装Java软件开发工具包(SDK)点击: http://www.oracle.com/technetwork/java/javase/downloads/index.html. 我们假设本教程中安装和使用Java1.7.0_25版本。 第二步:设置JAVA环境 设置JAVA_HOME环境变量指向的基本目录的位置,在你的机器上安装Java。例如: OS 输出 Windows 设置环境变量 JAVA_HOME 为 C:\Program Files\Java\jdk1.7.0_25 Linux export JAVA_HOME=/usr/local/java-current Mac export JAVA_HOME=/Library/Java/Home 添加Java编译器的位置,系统路径。 OS 输出 Windows Append the string; C:\Program Files\Java\jdk1.7.0_25\bin to the end of the system variable, Path. Linux export PATH=$PATH:$JAVA_HOME/bin/ Mac not required 验证Java安装使用命令java-version如上所述。 第3步:下载TestNG的归档文件 下载最新版本的TestNG的jar文件,详细请点击访问 http://www.testng.org.。在写这篇教程的时候,我下载TestNG中-6.8.jar,并将 testng-6.8.jar 其复制到 C:\>TestNG 目录。 OS 压缩文件名 Windows testng-6.8.jar Linux testng-6.8.jar Mac testng-6.8.jar 步骤4:设置TestNG的环境 设置TESTNG_HOME环境变量指向TestNG的jar 存放在您的机器上的基本目录位置。假设,我们已经储存了testng-6.8.jar, TestNG各种操作系统上的文件夹如下: OS 输出 Windows Set the environment variable TESTNG_HOME to C:\TESTNG Linux export TESTNG_HOME=/usr/local/TESTNG Mac export TESTNG_HOME=/Library/TESTNG 第5步:设置CLASSPATH变量 设置CLASSPATH环境变量指向TestNG的jar文件位置。假设,我们已经储存了testng-6.8.jar, TestNG在各种操作系统上的文件夹如下: OS 输出 Windows 设置环境变量 CLASSPATH 为 %CLASSPATH%;%TESTNG_HOME%\testng-6.8.jar; Linux export CLASSPATH=$CLASSPATH:$TESTNG_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值