-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Clarify differences between DisplayName & Name throughout JUnit 5 #153
Comments
We discussed the issue today in a team call. I try to summarize. Current situation:
The behaviour described above seems inconsistent. I therefore suggest the following changes:
Having a simpler form of default display name will also simplify a computed "prettification" of display names (see #162). |
@jlink, thanks for the detailed write up! I haven't investigated the proposal in detail with regard to the code and any possible ramifications, but in general the proposal seems like a good idea. |
Rethinking the whole issue, I think that In |
New ProposalI also think we should not have two competing naming concepts. In addition, as @akozlova has expressed in #172, IntelliJ wants to know whether a name was explicitly set by users (using To limit the number of methods we'll have to add to public final class TestName {
public static TestName implicit(String name) {
return implicit(name, name);
}
public static TestName implicit(String shortName, String longName) {
return new TestName(false, shortName, longName);
}
public static TestName explicit(String name) {
return explicit(name, name);
}
public static TestName explicit(String shortName, String longName) {
return new TestName(true, shortName, longName);
}
private final boolean explicit;
private final String shortName;
private final String longName;
public TestName(boolean explicit, String shortName, String longName) {
this.explicit = explicit;
this.shortName = shortName;
this.longName = longName;
}
public boolean isExplicit() {
return explicit;
}
public String getShortName() {
return shortName;
}
public String getLongName() {
return longName;
}
@Override
public String toString() {
return longName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TestName testName = (TestName) o;
return explicit == testName.explicit &&
Objects.equals(shortName, testName.shortName) &&
Objects.equals(longName, testName.longName);
}
@Override
public int hashCode() {
return Objects.hash(explicit, shortName, longName);
}
} @junit-team/junit-lambda What do you think? |
This looks like a useful abstraction. One detail: I would forego the |
After reading through all of the comments and reflecting on the proposals, I agree with most everything that @jlink proposed. The display name is exactly that: what IDEs and build tools should display as the name in human readable form. Consequently, IDEs and build tools should never rely on the display name when determining how to structure the test tree in a UI. IDEs and build tools must therefore rely on the information provided via the concrete Furthermore, this line of reasoning makes the proposal in #172 obsolete: IDEs should not care about the source of the display name or its format. They should simply display it. Proposal
Default Display Name SemanticsFor each common test element type, the following listing provides a description as well as a concrete example based on the
package org.example;
public class TopLevel {
static class StaticNested {}
@Nested
class Inner {}
@Test
void method1() {}
@Test
void method2(TestInfo testInfo) {}
@TestFactory
Stream<DynamicTest> dynamicTests() {
return Stream.of(new DynamicTest("dynamic test", () -> {}));
}
} @junit-team/junit-lambda, what do you think about this alternative proposal? |
One thing to keep in mind regarding test source: When you inherit a test method from a super class, the test source will point to the method in the super class. So it cannot be used to compute a "display name" by the IDE. Having said that, I am fine with this proposal! One minor thing: Omitting the package name from the display name of a top-level class only makes sense when packages are actually present in the tree of test descriptors. As we don't have them right now, I think we should keep using the fully-qualified class name. |
Team decision:
Note: the aforementioned modifications have already been made to the proposal. |
in progress |
This commit introduces Optional<Class<?>> getTestClass() and Optional<Method> getTestMethod() methods in TestInfo and ExtensionContext. The existing `Class<?> getTestClass()` method in ExtensionContext has simply been replaced, and the existing `Method getTestMethod()` method in TestExtensionContext has been removed. Issue: #153
This commit introduces Optional<Class<?>> getTestClass() and Optional<Method> getTestMethod() methods in TestInfo and ExtensionContext. The existing `Class<?> getTestClass()` method in ExtensionContext has simply been replaced, and the existing `Method getTestMethod()` method in TestExtensionContext has been removed. Issue: #153
This issue is blocked until #58 has been completed and merged into |
This issue is no longer blocked since #58 has been completed. |
This commit introduces Optional<Class<?>> getTestClass() and Optional<Method> getTestMethod() methods in TestInfo and ExtensionContext. The existing `Class<?> getTestClass()` method in ExtensionContext has simply been replaced, and the existing `Method getTestMethod()` method in TestExtensionContext has been removed. Issue: #153
This commit revises the default display generation for test methods so that the following format is used instead of simply the method name. - <name>([comma separated list of simple names for parameter types]) Issue: #153
@junit-team/junit-lambda, PR #279 has been rebased on |
Do we need to discuss display names of classes in a team call again (cf. comment on #279) or are we confident enough that using simple names is better? |
I didn't make the switch to simple names for classes in the PR yet, but I think we can be confident enough that it's likely the correct decision for the long term. Besides, getting this change in as early as possible with result in the least element of surprise should we decide to do so later. And... this gives us a lot of time (over half a year) to gain feedback from the community. |
So, @marcphilipp, does that mean this PR is good to go (along with the switch to simple names for all classes)? 😉 |
I'll take a more thorough look at the PR tonight and let you know. 😉 |
thanks |
This commit introduces Optional<Class<?>> getTestClass() and Optional<Method> getTestMethod() methods in TestInfo and ExtensionContext. The existing `Class<?> getTestClass()` method in ExtensionContext has simply been replaced, and the existing `Method getTestMethod()` method in TestExtensionContext has been removed. Issue: #153
This commit revises the default display generation for test methods so that the following format is used instead of simply the method name. - <name>([comma separated list of simple names for parameter types]) Issue: #153
This commit revises the default display name generation for test classes so that the following formats are used instead of the fully qualified class names (FQCN). - Top-level and static classes: the FQCN with the package name and separating "." removed. - @nested classes: the simple name for the class. Issue: #153
I understand the need for a UniqueId and a DisplayName, which I guess is only unique among the children of single a parent. But what is the Name for?
Related To
The text was updated successfully, but these errors were encountered: