0% found this document useful (0 votes)
12 views

Java - TestNG

Uploaded by

Mariem Nabli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Java - TestNG

Uploaded by

Mariem Nabli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

01/10

Java - TestNG
Cheat Sheet

alphabin.co
02/10

TestNG Annotations:
@Test:
Denotes a test method.

@BeforeClass:
Runs once before the first test method in the
current class.

@AfterClass:
Runs once after all the test methods in the
current class.

@BeforeMethod:
Runs before each test method.

alphabin.co
03/10

@AfterMethod:
Runs after each test method.

@BeforeSuite:
Runs once before all tests in the suite.

@AfterSuite:
Runs once after all tests in the suite.

@BeforeTest:
Runs once before all tests within the current
<test> tag.

@AfterTest:
Runs once after all tests within the current
<test> tag.

alphabin.co
04/10

TestNG Assertions:
assertEqual(String actual, String expected);
Asserts that two strings are equal or not.

assertEquals(boolean actual, boolean expected);


Asserts that two boolean values are equal

assertTrue(boolean condition);
Asserts that condition is true.

assertFalse(boolean condition);
Asserts that condition is false.

assertNull(Object object);
Asserts that an object is null.

alphabin.co
05/10

assertNotNull(Object object);
Asserts that an object is not null.

assertSame(Object actual, Object expected);


Asserts that two objects refer to the same object

assertNotSame(Object actual, Object expected);


Asserts that two objects do not refer to
the same objects

alphabin.co
06/10

TestNG Attributes:
priority:
Set to prioritize the test method for execution.

enabled:
Set to ignore the test method for execution.

invocationCount:
Set to run the test method multiple times.

invocationtimeOut:
Maximum time period provided the test case
for all the invocations count set.

alphabin.co
07/10

timeout
Total time period provided to the test
case to completely execute its test case.

dependsOnMethods:
Inject dependency to the test methods.

groups
To categorize the test case to execute
under a specified group.

dependsOnGroups:
Inject dependency to the test methods based
on the groups to execute.

alphabin.co
08/10

TestNG Configuration:
testng.xml:
XML file to configure TestNG tests.

<suite>:
Represents a suite of tests.

<test>
Represents a test within a suite.

<classes>:
Specifies the classes to be included in a test.

alphabin.co
09/10

<packages>:
Specifies the packages to be included in a test.

<methods>:
Specifies the methods to be included in a test.

<groups>:
Specifies the groups to be included in a test.

<listeners>:
Specifies the listeners to be used in a test.

alphabin.co
10/10

Was This
Helpful

alphabin.co

You might also like