Exam 2 - L14 - Introduction to JUnit Flashcards

1
Q

What is JUnit?

A

A unit testing framework for Java

It helps you write and run automated tests to make sure code works correctly

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

What are the key features of JUnit 5?

A

Modularity, improved architecture, extensibility, enhanced assertions.

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

What does ‘@Test’ do in JUnit 5?

A

Marks a method as a test method to be run by JUnit.

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

When is @BeforeEach used?

A

Runs before every test method to set up test data.

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

What does @AfterAll do?

A

Runs once after all tests have completed, used for cleanup.

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

What is a best practice when naming tests?

A

Use meaningful names like ‘shouldReturnTrueWhenInputIsValid’

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

What is the Arrange-Act-Assert pattern?

A

A simple testing pattern used to organize unit tests.

Arrange: Set up everything you need: Create objects, initialize variables, configure the environment.

Act: Do the thing you are testing : call the method under test.

Assert : Check that the result is what you expect. Verify the outcome matches the expected behavior.

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

What pattern should you follow when writing a test?

A

Arrange-Act-Assert

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

Why avoid putting logic in tests?

A

Tests should only check results, not do complex operations.

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

What is a parameterized test in JUnit 5?

A

A test that runs multiple times with different inputs

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

How do you run JUnit 5 tests?

A

Using an IDE, Maven/Gradle, or the command line.

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

What tools help with mocking and coverage?

A

Mockito (mocking), JaCoCo (coverage).

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

What’s an example of a simple assertion?

A

assertEquals(4, 2 + 2);

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

Why isn’t 100% code coverage always a good goal?

A

You can have 100% coverage but still have bad or useless tests.

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

How does Maven know which files are tests?

A

Using ‘<include>**/*Test.java</include.>' in 'pom.xml'</include>

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

What does @Disabled do?

A

Skips or disables a test

17
Q

What does ‘@ExtendWith’ allow you to do?

A

Add custom extensions to enhance JUnit behavior