New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify implementation of self-contained dynamic tests #3261
Comments
|
Yes, @sbrannen and me brainstormed the interface and additional methods in a 1:1 yesterday. |
@FunctionalInterface
interface NamedExecutable<T extends NamedExecutable<T>> extends Named<T>, Executable {
@Override
public String getName() {
return this instanceof Record ? toString() : "Override getName() to generate a better name for " + this;
}
@Override
public default T getPayload() {
return (T) this;
}
} 🤔 |
Great idea. I usually define an explicit name as I value properly readable test names, but I agree that a record's |
|
Please note that the name of the We may well want to come up with a more descriptive name if we implement this feature. |
✨Multi-release JAR magic to the rescue.✨ Or lifting the baseline to 17... |
Team decision: Add |
Hello @marcphilipp , @odrotbohm, I'll try to summarize the discussion and ask a short question at the end. public static <T> Stream<DynamicTest> stream(
Iterator<T> inputGenerator,
Function<? super T, String> displayNameGenerator,
ThrowingConsumer<? super T> testExecutor
) { ... }
public static <T> Stream<DynamicTest> stream(
Stream<T> inputStream,
Function<? super T, String> displayNameGenerator,
ThrowingConsumer<? super T> testExecutor
) { ... }
public static <T> Stream<DynamicTest> stream(
Iterator<? extends Named<T>> inputGenerator,
ThrowingConsumer<? super T> testExecutor
) { ... }
public static <T> Stream<DynamicTest> stream(
Stream<? extends Named<T>> inputStream,
ThrowingConsumer<? super T> testExecutor
) { ... } As I understand, for this issue, the idea would be to add two more methods here. They will be using the new interface NamedExecutable that encapsulates all 3 parameters (the data, the names and the test executor functions): public static <T extends NamedExecutable<T>> Stream<DynamicTest> stream(
NamedExecutable<T>... inputGenerator
) { ... }
public static <T extends NamedExecutable<T>> Stream<DynamicTest> stream(
Stream<? extends NamedExecutable<T>> inputGenerator
) { ... } Since the current api exposes methods accepting Stream and Interator, should it be the same for the new ones for consistency reasons? I mean having Let me know what you think and if I can try looking into it. |
Introduce new interface NamedExecutable that associates a name, a payload and an Executable. This was introduced to help colocate test's diplayName, payload, and testExecutor in one place. Concrete usage of this interface is in the next commit. Issue: junit-team#3261
Introduce two methods in the class DynamicTest to generate a stream of DynamicTests from a Stream/Iterator of NamedExecutables. Instead of passing an inputStream, a displayNameGenerator and a testExecutor separately, these two additional methods will allow you to pass one Iterator/Stream of a NamedExecutable. Unlike the Named interface, the NamedExecutable can colocate assertion callbacks in one container using the execute method. Issue: junit-team#3261
Write new changes to the release notes for 5.11M1 and add a simple demo in DynamicTestsDemo. Issue: junit-team#3261
Introduce new interface NamedExecutable that associates a name, a payload and an Executable. This was introduced to help colocate test's diplayName, payload, and testExecutor in one place. Concrete usage of this interface is in the next commit. Issue: junit-team#3261
Introduce two methods in the class DynamicTest to generate a stream of DynamicTests from a Stream/Iterator of NamedExecutables. Instead of passing an inputStream, a displayNameGenerator and a testExecutor separately, these two additional methods will allow you to pass one Iterator/Stream of a NamedExecutable. Unlike the Named interface, the NamedExecutable can colocate assertion callbacks in one container using the execute method. Issue: junit-team#3261
Write new changes to the release notes for 5.11M1 and add a simple demo in DynamicTestsDemo. Issue: junit-team#3261
@TestFactory
s andDynamicTests
provide API to implement multiple test probes that will become individual tests. They're centered around the idea that one would create test fixtures as instances of types and provide API to then define the naming of the test and the actual assertion:There are a few things to note here:
getPayload()
to return the instance itself to satisfyNamed
although that method doesn't play into the signature ofDynamicTest.stream(…)
as the elements of the stream are handed into the callable.Assuming an extension of
Named
looking like this existed:a bit of syntactical sugar on
DynamicTest
:Would allow us to reduce the very first code sample to:
This allows to define parameterize test fixtures nicely and colocate the assertions within a type and the test factory method's responsibility is reduced to set up the individual probes.
The text was updated successfully, but these errors were encountered: