JUnit Flashcards
What is JUnit?
JUnit is a unit testing framework for the Java programming language
What is TDD?
Test Driven Development (TDD) is a software development approach in which test cases are developed to specify and validate what the code will do
What are the annotations in JUnit? And in what order should they be executed?
@BeforeClass - Executed before the first @Test method
@Before - Executed before all @Test methods in the JUnit test class
@Test - Executed for all @Test methods
@After - Executed after all @Test methods
@AfterClass - Executed after all the @Test methods in the JUnit test class
Give and example of a test case
@Test public void addNumberTest(){ // Arrange Calculator calculator = new Calculator();
// Act int actualResult = calculator.addNumber(10, 20);
// Assert int expectedResult = 30; assertEquals(expectedResult, actualResult); }
How would you prevent a test from being run without commenting it out?
The @Disabled annotation disables a test without having to comment it out. Placed before the @Test annotation