Skip to content

Instrumented @Test's with @DisplayName can't be run individually #207

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

Closed
ktkopone opened this issue Feb 26, 2020 · 3 comments
Closed

Instrumented @Test's with @DisplayName can't be run individually #207

ktkopone opened this issue Feb 26, 2020 · 3 comments
Assignees
Labels

Comments

@ktkopone
Copy link

ktkopone commented Feb 26, 2020

When creating an instrumented test with @DisplayName, e.g.:

@Test
@DisplayName("displayName's display name")
public void displayName() { assertTrue(true); }

Attempting to run the test individually (via either IDE or command line) will error with:
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

Running the test from the class-level or higher will work as expected. The same test will also be runnable individually if it is a unit rather than android test.

Also note that @ParameterizedTest's do not have this issue when given a display name (which makes sense since they already involve display names afaik).

Env info:
android-junit5 plugin 1.5.2.0
mannodermaus.junit5 1.2.0
junit 5.5.2
androidx.test 1.2.0
gradle 6.2.1
android gradle 3.5.3

@PiotrSmietana89
Copy link

I have the same problem. I've noticed that replacing Test annotations with junit4 ones (replace org.junit.jupiter.api.Test with org.junit.Test) allows individual instrumented tests to run, both from IDE and command line. Running tests in a whole class works fine too (as long as there are no @nested classes). This is definitely not a solid workaround, as it breaks tests in @nested classes, but it might be a clue for contributors when working on a fix.

Another interesting observation, in test class with two tests (no @nested classes), if both have same @test annotations (either both @org.junit.jupiter.api.Test or both @org.junit.Test) then running all tests in a class runs both of them, but when they're mixed, only @org.junit.jupiter.api.Test runs.

public class ExampleTest {

@BeforeEach
public void setUp() {
}

// when running all tests in a class, this will run
@DisplayName("test 1")
@org.junit.jupiter.api.Test
public void test1() {
}

// but this will not
@DisplayName("test 2")
@org.junit.Test
public void test2() {
}

}

@mannodermaus mannodermaus self-assigned this Jul 27, 2021
@mannodermaus mannodermaus added this to the instrumentation-1.3.0 milestone Jul 27, 2021
@mannodermaus
Copy link
Owner

The ability to assign a @DisplayName to a test is hindering the interoperability when running a test in isolation, because the association to the original method is lost when it is mapped to the old-style world that Android's instrumentation is confined to. (This is actually very related to #199 in that sense!)

For the upcoming 1.3.0 release, you will be able to execute individual tests with @DisplayName correctly, but they will lose their formatting and fall back to the actual method name in the process. When they run together, the pretty name is retained, but they will lose it in isolation - that's a limitation of the instrumentation that we have to obey.

@mannodermaus
Copy link
Owner

Released in instrumentation 1.3.0! Please note that the new version requires JUnit 5.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants