JUnit Flashcards

1
Q

What is JUnit?

A

JUnit is a unit testing framework for the Java programming language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is TDD?

A

Test Driven Development (TDD) is a software development approach in which test cases are developed to specify and validate what the code will do

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the annotations in JUnit? And in what order should they be executed?

A

@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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give and example of a test case

A
@Test
    public void addNumberTest(){
        // Arrange
        Calculator calculator = new Calculator();
        // Act
        int actualResult = calculator.addNumber(10, 20);
        // Assert
        int expectedResult = 30;
        assertEquals(expectedResult, actualResult);
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you prevent a test from being run without commenting it out?

A

The @Disabled annotation disables a test without having to comment it out. Placed before the @Test annotation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly