Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

TestNG (1)-- start

Shulou Source: shulou.com Published: 2022-06-03 05:25:56 09月24日 Update

You can get information from http://testng.org/doc/documentation-main.html.

I. brief introduction

TestNG is the acronym of test next generation, that is, the next generation of testing technology, if you have come into contact with junit or nunit, it may be easier to understand, but I believe there are many people like me, have not touched, pure rookie, in that case, step by step, start with the most basic.

TestNG is an annotation-based testing framework that can be used for both unit testing and integration testing.

A complete test consists of three steps:

Write test business logic and insert TestNG annotations into the code

Add your own test information to testng.xml or build.xml

Run TestNG.

Note: list of annotation programs supported by TestGN:

-- @ BeforeSuite,@BeforeTest,@BeforeClass,@BeforeMethod,@BeforeGroups

-- @ AfterSuite,@AfterTest,@AfterClass,@AfterClass,@AfterGroups

-- @ DataProvider

-- @ ExpectedExceptions

-- @ Factory

-- @ Test

-- @ Parameters

II. TestNG.xml Foundation

TestNG.xml is a configuration file from which the testNG runtime gets information, such as which method in which class to run, and so on. If you don't have a writing prompt when writing testNG.xml, you can add it to the head:

First understand some basic concepts, do not understand it, first look at:

A suite (suite) is a xml file (although the title is testNG.xml, do not be limited by it, the name can be arbitrarily chosen), it can be composed of one or more tests, marked as

A test (test) consists of one or more classes marked as

A class (class) consists of one or more methods marked as

Method (method) is a java method marked by @ Test in your code.

As mentioned earlier, we can specify the configuration of the test we run this time in the xml file. For example, we can specify the package name, class name, method name, and so on. Look at a xml file first and have an impression:

As you can see, this suite contains two test, and the second test has two class.

Tags: Tests files methods tags runs information multiple two code foundation contact configuration it doesn't matter in that case next generation business middle finger people and unit impression. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno Shulou Information Shulou Tech Info macOS