Skip to content
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

Test class is not enclosed #41

Closed
csekol opened this issue May 27, 2020 · 3 comments · Fixed by #86
Closed

Test class is not enclosed #41

csekol opened this issue May 27, 2020 · 3 comments · Fixed by #86

Comments

@csekol
Copy link

csekol commented May 27, 2020

Hi,

I tried to execute the test interfaces from https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-interfaces-and-default-methods, but I got an exception:

[info] Test com.example.StringTests#returnsNegativeNumberWhenComparedToLargerValue() started
[error] Test com.example.StringTests failed: java.lang.RuntimeException: Test class com.example.ComparableContract is not enclosed by com.example.StringTests, took 0.036s
[error]     at net.aichler.jupiter.internal.event.TaskName.nestedSuiteId(TaskName.java:135)
[error]     at net.aichler.jupiter.internal.event.TaskName.of(TaskName.java:116)
[error]     at net.aichler.jupiter.internal.event.Dispatcher.lambda$executionFinished$2(Dispatcher.java:99)
[error]     at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
[error]     at net.aichler.jupiter.internal.event.Dispatcher.executionFinished(Dispatcher.java:95)
[error]     ...
[info] Test run finished: 1 failed, 0 ignored, 6 total, 0.115s

Is this an issue?

Thanks,
csekol

@D3Castro
Copy link

D3Castro commented Sep 6, 2022

I'm having this exact issue stemming from running suites, is there a way to mitigate this issue?

@ken1ma
Copy link

ken1ma commented Nov 13, 2022

I have the same stack trace with a test class that inherits @Nested inner classes

class BaseTests {
  @Nested class Foo {
    @Test void bar() {
    }
  }
}

class DerivedTests extends BaseTests {
}

I'm currently avoiding the exception by modifying

        if (!className.startsWith(testSuite)) {
            throw new RuntimeException(
                    "Test class " + className + " is not enclosed by " + testSuite);
        }

with

        if (!className.startsWith(testSuite)) {
            // ad-hoc fix
            var dollar = className.indexOf('$');
            if (dollar >= 0)
                return className.substring(dollar);

            throw new RuntimeException(
                    "Test class " + className + " is not enclosed by " + testSuite);
        }

(this seems to be working with more than one level of @Nested)

https://github.com/sbt/sbt-jupiter-interface/blob/0.11.1/src/library/src/main/java/net/aichler/jupiter/internal/event/TaskName.java#L134-L137

@maichler
Copy link
Contributor

Hi and thank you for providing another sample.

When I run both samples as a unit test in the library project, the exception isn't thrown. Only when I add them to the scripted tests. Not sure what's going on yet, might be something in how the tests are collected by the TestRunner in the library compared to SBT for scripted tests?

Have to investigate further.

eed3si9n added a commit to eed3si9n/sbt-jupiter-interface that referenced this issue Jul 28, 2024
As far as I can tell interface works fine.
@eed3si9n eed3si9n mentioned this issue Jul 28, 2024
eed3si9n added a commit that referenced this issue Jul 28, 2024
As far as I can tell interface works fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants