| CARVIEW |
Select Language
HTTP/2 301
date: Tue, 30 Dec 2025 12:17:42 GMT
content-type: text/html
location: https://junit.org/junit4/
server: cloudflare
x-github-request-id: 4F6C:258884:65E54B1:6D3E81B:6953C2E5
cf-cache-status: DYNAMIC
referrer-policy: strict-origin-when-cross-origin
strict-transport-security: max-age=2592000; includeSubDomains
x-content-type-options: nosniff
content-security-policy: frame-ancestors 'self' *.javadoc.io javadoc.io
permissions-policy: geolocation=(), camera=(), microphone=()
cf-ray: 9b6179ba884a9ac4-BLR
HTTP/1.1 301 Moved Permanently
Date: Tue, 30 Dec 2025 12:17:42 GMT
Content-Length: 0
Connection: keep-alive
Location: https://junit.org/junit4/
X-Content-Type-Options: nosniff
Vary: accept-encoding
Content-Security-Policy: frame-ancestors 'self' *.javadoc.io javadoc.io
Permissions-Policy: geolocation=(), camera=(), microphone=()
Referrer-Policy: strict-origin-when-cross-origin
Server: cloudflare
CF-RAY: 9b6179bf3df1c1ae-BLR
HTTP/2 200
date: Tue, 30 Dec 2025 12:17:42 GMT
content-type: text/html; charset=utf-8
server: cloudflare
x-origin-cache: HIT
last-modified: Wed, 26 Nov 2025 13:15:34 GMT
vary: Accept-Encoding
access-control-allow-origin: *
content-security-policy: frame-ancestors 'self' *.javadoc.io javadoc.io
expires: Tue, 30 Dec 2025 12:27:42 GMT
cache-control: max-age=600
permissions-policy: geolocation=(), camera=(), microphone=()
x-proxy-cache: MISS
x-github-request-id: 4F6C:258884:65E5515:6D3E879:6953C2E6
cf-cache-status: DYNAMIC
referrer-policy: strict-origin-when-cross-origin
strict-transport-security: max-age=2592000; includeSubDomains
x-content-type-options: nosniff
content-encoding: gzip
cf-ray: 9b6179bf4a049ac4-BLR
JUnit – About
‹
›
- JUnit 4
- /
- About
- Last Published: 2025-06-24
- |
- Version: 4.13.2
JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.
JUnit 4 is in maintenance mode.
At this point, only critical bugs and security issues will be fixed.
All other issues and PRs will therefore be declined.
For ongoing development, please check out the junit-framework repository.
@Test
public void newArrayListsHaveNoElements() {
assertThat(new ArrayList<Integer>().size(), is(0));
}
@Test
public void sizeReturnsNumberOfElements() {
List<Object> instance = new ArrayList<Object>();
instance.add(new Object());
instance.add(new Object());
assertThat(instance.size(), is(2));
}
Annotations
Start by marking your tests with @Test.
@Test
public void lookupEmailAddresses() {
assertThat(new CartoonCharacterEmailLookupService().getResults("looney"), allOf(
not(empty()),
containsInAnyOrder(
allOf(instanceOf(Map.class), hasEntry("id", "56"), hasEntry("email", "[email protected]")),
allOf(instanceOf(Map.class), hasEntry("id", "76"), hasEntry("email", "[email protected]"))
)
));
}
Hamcrest matchers
Make your assertions more expressive and get better failure reports in return.
Welcome
Usage and Idioms
- Assertions
- Test Runners
- Aggregating tests in Suites
- Test Execution Order
- Exception Testing
- Matchers and assertThat
- Ignoring Tests
- Timeout for Tests
- Parameterized Tests
- Assumptions with Assume
- Rules
- Theories
- Test Fixtures
- Categories
- Use with Maven
- Multithreaded code and Concurrency
- Java contract test helpers
- Continuous Testing
Third-party extensions
- Custom Runners
- net.trajano.commons:commons-testing for UtilityClassTestUtil per #646
- System Rules – A collection of JUnit rules for testing code that uses java.lang.System.
- JUnit Toolbox - Provides runners for parallel testing, a PoolingWait class to ease asynchronous testing, and a WildcardPatternSuite which allow you to specify wildcard patterns instead of explicitly listing all classes when you create a suite class.
- junit-quickcheck - QuickCheck-style parameter suppliers for JUnit theories. Uses junit.contrib's version of the theories machinery, which respects generics on theory parameters.