Skip to content

Instantly share code, notes, and snippets.

@codification
Last active February 3, 2018 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codification/35b7aaab3cfbabac6aafcfdc8e6b01e6 to your computer and use it in GitHub Desktop.
Save codification/35b7aaab3cfbabac6aafcfdc8e6b01e6 to your computer and use it in GitHub Desktop.
Trying out closures as tests in Java8/junit5
import org.junit.jupiter.api.Assertions;
public class FirstTest extends FuncTest {
{{
describe("A test", () -> {
Assertions.assertTrue(() -> true);
});
describe("Another test", () -> {
Assertions.assertAll(
() -> {},
() -> {}
);
});
}}
}
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.function.Executable;
import java.util.LinkedList;
import java.util.Queue;
import java.util.stream.Stream;
public class FuncTest {
private final Queue<DynamicTest> tests = new LinkedList<>();
public void describe(String name, Executable test) {
tests.add(DynamicTest.dynamicTest(name, test));
}
@TestFactory
Stream<DynamicTest> tests() {
return tests.stream();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment