@Test
The JUnit annotation that marks a method as a test to discover and run.
In more detail
Test methods need no particular name, so name them after the behaviour they check, such as greets_a_name. Each runs on a fresh instance of the test class, which keeps tests independent.
Example
@Test void greets_a_name() { assertEquals("Hello Ada", Greeting.text("Ada")); }Related terms
- JUnit — The standard testing framework for Java, which discovers methods marked @Test, runs them and reports each failure with the test's name.
- Java annotation — A marker starting with @, such as @Test or @Service, that attaches information to code for the compiler, tools or frameworks to act on.
- assertion — A check that a condition is true, which stops a test or program with a failure if it is false.
Taught in
- Testing Basics With JUnit 5 — Modern Java: Virtual Threads & High-Throughput Services
- Fluent Assertions With AssertJ — Modern Java: Virtual Threads & High-Throughput Services