01/10
alphabin.co
Java - TestNG
Cheat Sheet
+
TestNG Annotations:
alphabin.co
02/10
@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.
03/10
alphabin.co
@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.
@AfterMethod:
Runs after each test method.
@AfterTest:
Runs once after all tests within the current
<test> tag.
04/10
alphabin.co
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.
Asserts that condition is false.
assertNull(Object object);
Asserts that an object is null.
assertFalse(boolean condition);
05/10
alphabin.co
Asserts that two objects do not refer to
the same objects
assertSame(Object actual, Object expected);
Asserts that two objects refer to the same object
assertNotSame(Object actual, Object expected);
Asserts that an object is not null.
assertNotNull(Object object);
06/10
alphabin.co
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.
07/10
alphabin.co
To categorize the test case to execute
under a specified group.
dependsOnMethods:
Inject dependency to the test methods.
groups
Total time period provided to the test
case to completely execute its test case.
timeout
dependsOnGroups:
Inject dependency to the test methods based
on the groups to execute.
08/10
alphabin.co
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.
09/10
alphabin.co
<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.
10/10
Was This
Helpful
alphabin.co

java testng cheat sheet best way to prepare

  • 1.
  • 2.
    TestNG Annotations: alphabin.co 02/10 @Test: Denotes atest 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.
  • 3.
    03/10 alphabin.co @BeforeSuite: Runs once beforeall tests in the suite. @AfterSuite: Runs once after all tests in the suite. @BeforeTest: Runs once before all tests within the current <test> tag. @AfterMethod: Runs after each test method. @AfterTest: Runs once after all tests within the current <test> tag.
  • 4.
    04/10 alphabin.co 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. Asserts that condition is false. assertNull(Object object); Asserts that an object is null. assertFalse(boolean condition);
  • 5.
    05/10 alphabin.co Asserts that twoobjects do not refer to the same objects assertSame(Object actual, Object expected); Asserts that two objects refer to the same object assertNotSame(Object actual, Object expected); Asserts that an object is not null. assertNotNull(Object object);
  • 6.
    06/10 alphabin.co TestNG Attributes: priority: Set toprioritize 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.
  • 7.
    07/10 alphabin.co To categorize thetest case to execute under a specified group. dependsOnMethods: Inject dependency to the test methods. groups Total time period provided to the test case to completely execute its test case. timeout dependsOnGroups: Inject dependency to the test methods based on the groups to execute.
  • 8.
    08/10 alphabin.co TestNG Configuration: testng.xml: XML fileto 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.
  • 9.
    09/10 alphabin.co <packages>: Specifies the packagesto 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.
  • 10.