TestNG Notes
TestNG Notes
-------
TESTNG.XML = To create and handle multiple test classes . to configure the complete
test suite in a single file
Adv :
-----
Multiple test cases can be grouped more easily by converting them into testng.xml
file. (grouped = testng.xml)
In which you can make priorities which test case should be executed
first.
The same test case can be executed multiple times without loops just by using
keyword called 'invocation count. (MultipleTimes = invocation count)
you can execute multiple test cases on multiple browsers, i.e., cross browser
testing. (Multiple Browser)
Suppose you have two test cases , 'testGuru99TC1' and 'testGuru99TC2' and you want
to execute test case 'testGuru99TC2' before 'testGuru99TC1'.
In that case we will use 'dependsOnMethods' attribute to make dependency and order
of execution. (dependsOnMethods)
There are :
ISuiteListener,
ITestListener .
IConfigurable ,
IConfigurationListener ,
IAnnotationTransformer ,
IAnnotationTransformer2
DataProvider :
Same Testcase will run multiple number of times we should use data providers
TDD can be defined as a programming practice that instructs developers to write new
code only if an automated test has failed.
This avoids duplication of code. TDD means “Test Driven Development”.
The primary goal of TDD is to make the code clearer, simple and bug-free.
TESTNG :
TestNG Listeners are mainly used in generating customized reports and logs. Below
are the list of listeners provided TestNG. Each interface is having different
abstract methods which can be overridden as per our requirement.
IExecutionListener
This TestNG Listener monitors the begining and ending of the TestNG run. This has
two methods onExecutionStarts() and onExecutionEnd(). onExecutionStarts() method
will be invoked before TestNG starts executing the test suites and onExecutionEnd()
method will be invoked after TestNG finishes executing all the test suites.
IAnnotationTransformer
This TestNG Listener allows us to modify TestNG annotations and configure further.
IInvokedMethodListener
This TestNG Listener is for all the methods. It will be invoked before and after of
any method of TestNG.
IMethodInterceptor
This TestNG Listener is used to modify the list of test methods to be run in
TestNG. We can select group of test methods from the given list using this and
ignore other test methods.
IHookable
This TestNG Listener is used to implement your test methods with specific security
manager. If a test class implements this interface, its run() method will be
invoked instead of each @Test method found.
IReporter
This TestNG Listener is used for generating the report at the end of test suite
execution.
ISuiteListener
This TestNG Listener is for test suite and this listener contains two methods
onStart() and onFinish(). onStart() method will be invoked before executing the
Suite and onFinish() will be invoked at the end of the Suite execution.
ITestListener
This TestNG Listener is for test method and this contains methods onStart(),
onFinish(), onTestSuccess(), onTestFailure(), onTestSkipped() and
onTestFailedButWithinSuccessPercentage().