Sobes.tech
Junior — Middle

What annotations have you used when creating automated tests?

sobes.tech AI

Answer from AI

The following annotations are often used in automated testing:

  • @Test — marks a method as a test.
  • @Before and @BeforeEach — methods that run before each test to prepare the environment.
  • @After and @AfterEach — methods that run after each test for cleanup.
  • @BeforeClass and @BeforeAll — run once before all tests in the class.
  • @AfterClass and @AfterAll — run once after all tests.
  • @Ignore — skips the test.
  • In Android UI tests, @RunWith(AndroidJUnit4.class) is often used to specify the test runner.

Example in JUnit 4:

@RunWith(AndroidJUnit4.class)
public class ExampleTest {

    @Before
    public void setUp() {
        // setup code
    }

    @Test
    public void testSomething() {
        // test code
    }

    @After
    public void tearDown() {
        // cleanup code
    }
}