Watch
2
0
Fork
You've already forked zelador
0
JUnit 5 cleaning service.
  • Java 99.4%
  • CSS 0.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Mark Raynsford 2e4a651697
Some checks are pending
main-RHEL10-x86_64-jdk25 / Build (push) Waiting to run
main-RHEL10-x86_64-jdk26 / Build (push) Waiting to run
main-RHEL9-x86_64-jdk25 / Build (push) Waiting to run
main-RHEL9-x86_64-jdk26 / Build (push) Waiting to run
Update workflows.
2026-07-31 18:43:01 +01:00
.forgejo Update workflows. 2026-07-31 18:43:01 +01:00
com.io7m.zelador.test_extension Begin next development iteration. 2024-05-10 17:50:10 +00:00
com.io7m.zelador.tests Use junit BOM. 2024-10-26 13:04:16 +00:00
src/site/resources Update site metadata. 2025-08-09 15:07:21 +00:00
.gitignore Update .gitignore. 2024-05-07 16:01:48 +00:00
checkstyle-filter.xml Initial version. 2023-06-27 21:04:15 +00:00
checkstyle-suppressions-1.0.dtd Initial version. 2023-06-27 21:04:15 +00:00
doc7m-books.json Add doc7m-books.json 2026-07-31 18:36:52 +01:00
pom.xml Migrate project. 2026-06-27 10:14:45 +01:00
README-CHANGES.xml Mark release 1.0.0 2024-05-10 17:50:03 +00:00
README-LICENSE.txt Update LICENSE 2023-08-13 21:07:30 +00:00
README.in Migrate project. 2026-06-27 10:14:45 +01:00
README.md Migrate project. 2026-06-27 10:14:45 +01:00

zelador

Maven Central Maven Central (snapshot) Java Version

com.io7m.zelador

zelador

A minimalist JUnit 5 extension to register AutoCloseable resources that will be destroyed after tests finish executing.

Features

  • Written in pure Java 21.
  • OSGi ready.
  • JPMS ready.
  • ISC license.
  • High-coverage automated test suite.

Motivation

For whatever reason, JUnit 5 does not include any utility to register per-test resources and automatically have them cleaned up.

The zelador package provides a tiny JUnit 5 extension that allows for registering AutoCloseable objects that must be closed after tests finish executing.

Building

$ mvn clean verify

Usage

Annotate your test suite with @ExtendWith(ZeladorExtension.class). This will allow tests to get access to an injected CloseableResourcesType instance that can be used to register resources to be closed.

@ExtendWith(ZeladorExtension.class)
public final class ExampleTest
{
  @Test
  public void test0(
    final CloseableResourcesType resources)
  {
    var output = resources.addPerTestResource(Files.newOutputStream(...));
    ...
  }

  @Test
  public void test1(
    final CloseableResourcesType resources)
  {
    var output = resources.addPerTestClassResource(Files.newOutputStream(...));
    ...
  }
}

Resources added with addPerTestResource will be closed after the individual test has finished (as if it had been closed in an @AfterEach method).

Resources added with addPerTestClassResource will be closed after all tests in the class have finished (as if it had been closed in an @AfterAll method).

AutoCloseable is a functional interface and, as such, it's trivial to pass objects to the CloseableResourcesType class that do not implement AutoCloseable by simply using a method reference:

class NotReallyCloseable {
  public void finish() { ... }
}

NotReallyCloseable x;

resources.addPerTestResource(x::finish);