0% found this document useful (0 votes)
180 views3 pages

Junit5 LinkedIn Learning

JUnit is a unit testing framework for Java that allows developers to write testable code and ensure code behaves as expected. More than just unit testing is needed, as unit tests do not test the full application. Dependency injection in tests avoids duplicate code and makes tests loosely coupled. The @Test annotation is used to mark test methods, and assertions like assertEquals are used to check expected outcomes match actual ones.

Uploaded by

Solution Guru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
180 views3 pages

Junit5 LinkedIn Learning

JUnit is a unit testing framework for Java that allows developers to write testable code and ensure code behaves as expected. More than just unit testing is needed, as unit tests do not test the full application. Dependency injection in tests avoids duplicate code and makes tests loosely coupled. The @Test annotation is used to mark test methods, and assertions like assertEquals are used to check expected outcomes match actual ones.

Uploaded by

Solution Guru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LinkedIn Learning

Learning JUnit 5

1. What does unit testing do for code quality?


Unit testing improves the code quality and ensures that pieces of
code behave as expected, because the developer is forced to
write testable code.
2. Which description best describes JUnit?
JUnit is a unit testing framework for Java.
3. Why do we need more testing than just unit testing?
Because unit tests don't test that the application as a whole is
functioning as expected.
4. What are the advantages of TDD for your software?
TDD forces the developer to think thoroughly about the
implementation code before actually implementing a feature,
which leads to better code.
TDD ensures that the code is tested well and that all the
required testing methods are in place: unit tests, system tests,
integration tests, etc.
5. What is the JUnit method we can use to make sure that an
expected outcome matches an actual outcome?
assertEquals
6. What do we need to write on top of a test?
@Test
7. How can we influence the order of our tests?
using the @Order annotation and annotating our class with
@TestMethodOrder and the right argument
8. What happens when an assumption fails?
The test will be aborted.
9. What are nested tests used for?
to group unit tests
10. When does a test fail?
when an assertion is not met
11. How can we recognize annotations?
@
12. What is the third argument of an assertion that takes three
parameters?
a delta or a custom message
13. How can we influence the name appearing in the test
report?
@Displayname
14. What happens when the condition of, for example,
@EnabledOnJre is not met?
The test will be ignored.
15. What are the advantages of dependency injection?
Dependency injection avoids duplicate code and makes the tests
more loosely coupled.
16. How can we disable unit tests unconditionally?
@Disabled
17. How are parameterized tests different from repeated tests?
Tests are repeated with different parameters for parameterized
tests. Repeated tests are simply repeating the same test.
18. How can we repeat tests?
@RepeatedTest

19. What can be said about the order of the tests when parallel
execution is used?
Not a lot; they are executed parallel, but the exact order depends
on the machine the tests are running on.
20. What is the difference between the timeout annotation and
assertTimeout assertion?
The timeout annotation is timing the full method and the
assertTimeout only the execution of the assertion.
21. What plugin can we use for custom reports?
Surefire
22. What is the difference between BeforeAll and
BeforeEach?
BeforeAll is only executed once before all the tests and
BeforeEach before every test.
23. What needs to be done to get implementation code ready
for unit testing?
Make sure the code is testable. Long methods need to be split up
and a single piece of code needs to have a single responsibility.
The implementation code must also be deterministic.
24. What is Mockito used for?
to create mock objects for testing and write loosely coupled tests
that are really only testing the unit of code and not hidden
dependencies of that piece of code
25. Why do we need tests to be deterministic?
Otherwise they are not reliable since they are influenced by
circumstances.

You might also like