A brief introduction and use of Testng (2)

In the previous article, we said that the amount was too general. Here, according to my personal understanding, I will explain in detail what this TestNG is used for.

TestNG is a testing framework, so what functions can it achieve?

First we can manage our test class test methods etc. You can also control whether test methods are parallelized. Select use of test methods in a class, provide data-driven, provide test reports, etc.

Let's talk about a few commonly used 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 methods belonging to the class inside the <test> tag are run. 
@AfterTest : The annotated method will be run after all test methods belonging to the class inside the <test> tag have run. 
@BeforeGroups : List of groups that this configuration method will run before. This method is guaranteed to run before the first test method belonging to any of these groups is called. 
@AfterGroups : List of groups after which this configuration method will run. This method is guaranteed to run shortly after the last test method belonging to these groups is called. 
@BeforeClass : The annotated method will run before the first test method in the current class is called. 
@AfterClass : The annotated method will be run after all test methods of the current class have run. 
@BeforeMethod : The annotated method will be run before each test method. 

@AfterMethod : The annotated method will be run after each test method.

All the above annotations are used in the test code of java.

This is very simple and I will not write an example here.

Let's talk about several parameters of the configuration file xml.

name: the name of the suite (it will appear in the test report)
junit: whether to run
verbose in junit mode: how to output on the console, this setting will not affect the html version of the report
parallel: whether to use multi-threaded testing
configfailurepolicy: whether Continue to try or skip
the thread count after a failed run : if parallel is set, the number of threads can be set ) or test (if parallel="tests") set a wait time in milliseconds before skipfailedinvocationcounts : whether to skip failed calls data-provider-thread-coun : provide an integer range of thread pools in order to use parallel data object-factory : a class that extends IObjectFactory and is used to instantiate test objects







allow-return-values ​​: If set to true, the test case will be run and values ​​will be returned

These are very simple and I will not do specific experiments here. Let's see the time later, if there is time, I will write about its specific case.

In fact, these cases are available on Testng's official website, and they are very detailed.

I'm just making a note for myself here, so I'm writing a bit rough, please forgive me. I will write a complete write-up of the use of this framework in the future.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326016816&siteId=291194637