Middle
Which testing framework did you use — TestNG or JUnit?
sobes.tech AI
Answer from AI
I have used both frameworks — TestNG and JUnit. TestNG is more flexible and supports features such as test parameterization, dependent tests, parallel execution, and annotations with extended functionality. JUnit is simpler and widely used, especially JUnit 5, which also supports extensions and parameterization.
Example of a simple test in JUnit 5:
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CalculatorTest {
@Test
void addition() {
assertEquals(5, 2 + 3);
}
}
TestNG allows, for example, to set dependencies between tests:
import org.testng.annotations.Test;
public class SampleTest {
@Test
public void init() {
// initialization
}
@Test(dependsOnMethods = {"init"})
public void testMethod() {
// test that depends on init
}
}