TestNG入门指南

第1章        Introduction

The TestNG project aims to help developerstake the next step—the NG stands for “next generation”—enabling broader anddeeper test coverage that encompasses not only unit tests but also acceptance,functional, and integration tests.

·     TestNG is a testing framework written by Java and inspired from JUnit andNUnit, it is not only inherited existing functions from Junit as well as introducing some new functionality that make it more powerful and easier touse, to get more reliable, maintainable and testable codes.

Writing a test is typically a three-stepprocess:

·        Write the business logic of your test and insertTestNGannotations in your code.

·        Add the information about your test (e.g. theclass name, the groups you wish to run, etc...) in a testng.xmlfile or in build.xml.

·        Run TestNG.

The concepts used in this documentation areas follows:

·        A suite is represented by one XML file. It cancontain one or more tests and is defined by the <suite> tag.

·        A test is represented by <test> and cancontain one or more TestNG classes.

·        A TestNG class is a Java class that contains atleast one TestNG annotation. It is represented by the <class> tag and cancontain one or more test methods.

·        A test method is a Java method annotated by @Testin your source.

 

第2章        Download and installation

2.1  Pre-Requirement

TestNG requires JDK 5or higher.

 

2.2 TestNG Download and installation

You can download the current release versionof TestNG here http://testng.org/doc/download.html, Unpacking the zipdistribution to get TestNG decompression file, which includes the below subfiles:

·      Testng-5.14.1.jar(pleaseadd to your project directly, you may also not be able to successfully buildyour codes with this jar because TestNG official decided the releasedid not include all external jar files in order to keep the size down.)

·      Doc(TestNGtutorial material).

·      Examplecodes.

·      Testng sourcecodes.

·      Readme.

As a beginner, I highly recommend You startand write TestNG from example codes and docs(best materials).

For the Eclipse plug-in, we suggest using theupdate site:

·                    For Eclipse 3.4 and above, enter http://beust.com/eclipse.

·                    For Eclipse 3.3 and below, enterhttp://beust.com/eclipse1.

 

第3章        Annotations

@BeforeSuite

The annotated method will be run before all tests in this suite have run.

@AfterSuite

The annotated method will be run after all tests in this suite have run.

@BeforeTest

The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.

@AfterTest

The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.

@BeforeGroups

The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.

@AfterGroups

The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked.

@BeforeClass

The annotated method will be run before the first test method in the current class is invoked.

@AfterClass

The annotated method will be run after all the test methods in the current class have been run.

@BeforeMethod

The annotated method will be run before each test method.

@AfterMethod

The annotated method will be run after each test method.

@DataProvider           

Marks a method as supplying data for a test method. The annotated method must return an Object[][] where each Object[] can be assigned the parameter list of the test method.

@Factory

Marks a method as a factory that returns objects that will be used by TestNG as Test classes. The method must return Object[].

@Listeners

Defines listeners on a test class.

@Parameters

Describes how to pass parameters to a @Test method.

@Test

Marks a class or a method as part of the test.

 

 

 

 

 

 

 

第4章        TestNG Tutorial

4.1  Basic Usage

importjava.util.*;

importorg.testng.Assert;

importorg.testng.annotations.*;

 

publicclass TestNGTest1 {

 

    privateCollection collection;

 </

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值