Junit is the most common test framework for Java. It uses annotations to organize tests and make assertions. The document discusses how Junit can be integrated into projects using Maven or Eclipse, different ways to group tests, common assertions like assertEquals, and rules for handling things like temporary files and timeouts.
2. Junit introduction
● Samples in Github
– https://github.com/franck-benault/test-junit
● Junit is the most common tests framework for the java
language
● Based on annotations since version 4
● Tests organisation
● First assertion
● We often need other frameworks to write complete and
efficient tests
8. Junit rules
● Rules allow very flexible addition or redifinition of the
behavior of each test method in a test class.
● Tester can reuse or extend one of the provided Rules
(example system-rules a library of rules)
● Main rules
– TemporaryFolder rule
– ExternalResource rule
– Timeout rule
9. Temporary rules
● The temporaryFolder rule allows
– Creation of files
– Creation of folder
– Deletion of them when the test method finishes
@Rule
public TemporaryFolder folder = new TemporaryFolder();
10. Handling exceptions
● Fail with try-catch bloc
● @Test annotation
● Junit rule
● Catch-exception library
● Write its own annotation
11. Conclusion
● Junit is essential to write tests with de Java language
● There are a lot of additional frameworks which complete
Junit