Junior — Middle
Can you explain what TestNG is and how it is used in automated testing?
sobes.tech AI
Answer from AI
TestNG is a framework for automated testing in Java that allows creating and running tests with extended capabilities compared to JUnit. It supports annotations for defining test methods, grouping tests, parameterization, test dependencies, parallel execution, and report generation.
TestNG is widely used for functional, integration, and system testing. For example, you can annotate a method with @Test, specify that it depends on another test, or set parameters for running with different input data.
Example of a simple test with TestNG:
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
public class CalculatorTest {
@Test
public void testAddition() {
int result = 2 + 3;
assertEquals(result, 5);
}
}
TestNG allows flexible test management, making it a convenient tool for automation testing in Java projects.