Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to mark the method as a test method using TestNG.
Selenium Java
public class SampleTest { [1] public void testLogin() { // test code here } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @BeforeMethod or @AfterMethod instead of @Test for test methods.
Forgetting to add any annotation.
✗ Incorrect
The @Test annotation marks a method as a test method in TestNG.
2fill in blank
mediumComplete the code to run setup code before each test method.
Selenium Java
public class SampleTest { [1] public void setup() { // setup code here } @Test public void testLogin() { // test code here } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @BeforeClass which runs only once before all tests.
Using @AfterMethod which runs after tests.
✗ Incorrect
The @BeforeMethod annotation runs the method before each test method.
3fill in blank
hardFix the error in the code to run cleanup code after each test method.
Selenium Java
public class SampleTest { @BeforeMethod public void setup() { // setup code } @Test public void testLogin() { // test code } [1] public void cleanup() { // cleanup code } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @BeforeMethod instead of @AfterMethod for cleanup.
Using @Test annotation on cleanup method.
✗ Incorrect
The @AfterMethod annotation runs the method after each test method for cleanup.
4fill in blank
hardFill both blanks to run setup before and cleanup after each test method.
Selenium Java
public class SampleTest { [1] public void setup() { // setup code } @Test public void testLogin() { // test code } [2] public void cleanup() { // cleanup code } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up @BeforeMethod and @AfterMethod annotations.
Using @BeforeClass which runs only once before all tests.
✗ Incorrect
Use @BeforeMethod for setup before each test and @AfterMethod for cleanup after each test.
5fill in blank
hardFill all three blanks to create a test class with setup, test, and cleanup methods correctly annotated.
Selenium Java
public class SampleTest { [1] public void setup() { // setup code } [2] public void testLogin() { // test code } [3] public void cleanup() { // cleanup code } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Annotating test method with @BeforeMethod or @AfterMethod.
Forgetting to annotate setup or cleanup methods.
✗ Incorrect
Setup uses @BeforeMethod, test uses @Test, and cleanup uses @AfterMethod annotations.