Last active
February 3, 2018 13:19
-
-
Save codification/35b7aaab3cfbabac6aafcfdc8e6b01e6 to your computer and use it in GitHub Desktop.
Trying out closures as tests in Java8/junit5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.jupiter.api.Assertions; | |
public class FirstTest extends FuncTest { | |
{{ | |
describe("A test", () -> { | |
Assertions.assertTrue(() -> true); | |
}); | |
describe("Another test", () -> { | |
Assertions.assertAll( | |
() -> {}, | |
() -> {} | |
); | |
}); | |
}} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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