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

Introduce error handling mechanism for validation and discovery errors #242

Open
5 tasks
marcphilipp opened this issue May 6, 2016 · 31 comments
Open
5 tasks

Comments

@marcphilipp
Copy link
Member

marcphilipp commented May 6, 2016

Overview

Validation errors (e.g., for invalid @BeforeEach method declarations) should not abort the entire discovery phase. Instead the discovery phase should continue, with the error tracked and reported during the execution phase.

Areas of Applicability

Proposals

  1. Allow engines to track errors by creating a special type of TestDescriptor such as an AlwaysFailingTestDescriptor, DeadOnArrivalTestDescriptor, or ErrorReportingTestDescriptor.
    • Tracked errors for such a corresponding TestDescriptor could then be thrown as an exception during the execution phase instead of executing the corresponding container or test.
  2. Introduce a new property in TestDescriptor that signals an error that was encountered during the discovery phase.
  3. Pass a reporting object from the Launcher into each TestEngine to report errors.

Related Issues

Deliverables

@sbrannen
Copy link
Member

The same is true for invalid custom display names supplied by the user, as described in #743.

I will therefore update the description of this issue to reflect the broader scope.

@sbrannen sbrannen changed the title Revisit validation and exception handling in the JUnit 5 TestEngine Introduce exception handling mechanism for validation errors in JUnit Jupiter Mar 23, 2017
@sbrannen
Copy link
Member

FYI: I have introduced a minimum set of Deliverables.

@gaganis
Copy link
Contributor

gaganis commented Mar 23, 2017

I am thinking this reminds me the approach we took for vintage to handle multiple assertion errors using a MultipleFailuresError.

We could be possible that we could store all validation errors in a Throwable - using a MultipleFailuresError when there is more than one, that would be carried over to the execution phase and when this is nonEmpty we would throw the exception instead of executing the test.


It might also be worth considering for this mechanism to track all exceptions that occur while processing a single discovered test and throw it in the execution phase.

This way instead of the whole process stopping, we could still process the rest of the tests that encountered no problems and only fail on single tests.

PS While I was writing, this @sbrannen changed the title and description and now it sound more like what I am writing here! 😃

@sbrannen
Copy link
Member

@gaganis, thanks for sharing your ideas.

A few notes...

No need to use MultipleFailuresError.

We're on Java 8 and can use suppressed exceptions.

Plus, we already have a ThrowableCollector within the JUnit Jupiter engine that could potentially be used for this purpose as well.

@sbrannen sbrannen changed the title Introduce exception handling mechanism for validation errors in JUnit Jupiter Introduce exception handling mechanism for validation and discovery errors Apr 15, 2017
@sbrannen
Copy link
Member

The scope of this issue has been broadened in order to encompass the Platform as well.

@jlink
Copy link
Contributor

jlink commented Apr 15, 2017

Rather than using exceptions of any kind, having some kind of notification collector as a return or in/out parameter seems more flexible since any exception will stop an engine's discovery phase whereas many notifications are just warnings or pieces of information .

@sbrannen
Copy link
Member

Rather than using exceptions of any kind, having some kind of notification collector as a return or in/out parameter seems more flexible since any exception will stop an engine's discovery phase whereas many notifications are just warnings or pieces of information .

Good point!

I'll change the title of this issue accordingly.

@sbrannen sbrannen changed the title Introduce exception handling mechanism for validation and discovery errors Introduce error handling mechanism for validation and discovery errors Apr 15, 2017
@sbrannen
Copy link
Member

FYI: title and description have updated.

@stale
Copy link

stale bot commented Jun 5, 2021

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@GavinRay97
Copy link

Following up here on the issue posted at #2659 (whoops):

This behavior can cause quite a headache and be very confusing.
If I were to try to PR a minimal change which just did the below:

Map<String, JavaType> methodNameTypeMap = new Map()
for test in tests:
  methodNameTypeMap.insert(test.name, test.method.returnType)
  
when "test results are reported":
  for (testName, testFnType) in methodNameTypeMap.entries():
    if testFnType != "void" then:
      print(f"[WARNING]: Found test {testName} with type {testFnType}. JUnit only resolves tests of type void -- test was skipped")

How difficult would this change be to make as someone who didn't know the codebase?
The reason why I ask is because this leads to scenarios like these:

This was a multi-day investigation for me =/
I don't want anyone else to have to go through that again. Can we make this better for everyone?

@Marcono1234
Copy link
Contributor

Should this also cover @Suite? Its predicate class IsSuiteClass seems to silently ignore the class if the predicate does not match, despite being explicitly annotated.

@sbrannen
Copy link
Member

Yes, this should also apply to @Suite classes. I'll add that to this issue's description.

@simondean
Copy link

Hi. This is big issue when writing unit tests in Kotlin. It's really easy to create unit test in Kotlin that implicitly returns a none void return type. JUnit then just silently fails to run any of your Kotlin unit test that have a none void return type.

As an example, in a codebase with about 800 unit tests, I found that about 20 of the unit tests were being silently ignored by JUnit 5 because of this issue.

Here a repo with a minimal reproducible example for easily hitting this bug in Kotlin:

https://github.com/simondean/kotlin-junit-run-blocking-issue/blob/main/src/test/kotlin/IssueTest.kt

    @Test
    fun `also will be silently skipped`() = runBlocking {
        // This bug is not specific to Mockito but the bug is easily triggered by putting a verify() call at the end of a unit test
        val value = "anything"
       
       // Because verify() has a return value, so does the whole unit test, which causes JUnit to silently ignore the test (and any others like it in the codebase)
        verify(value).toString()
    }

See the following duplicate issues for more info/context:

Given this issue has been open for 5 years and it's arguably a more serious issue now that people are using Kotlin with JUnit, would it be worth boosting the priority of this issue? Thanks!

@sbrannen
Copy link
Member

sbrannen commented Oct 8, 2021

would it be worth boosting the priority of this issue? Thanks!

I've added the new label to signal to the team that it needs to be reconsidered.

@simondean
Copy link

Thanks @sbrannen

@timdawborn
Copy link

As an example, in a codebase with about 800 unit tests, I found that about 20 of the unit tests were being silently ignored by JUnit 5 because of this issue.

@simondean Out of interest, how did you detect these? I'm looking to implement similar logic and am searching for prior art currently before implementing something bespoke.

@stale
Copy link

stale bot commented Dec 22, 2022

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the status: stale label Dec 22, 2022
@stale
Copy link

stale bot commented Jan 12, 2023

This issue has been automatically closed due to inactivity. If you have a good use case for this feature, please feel free to reopen the issue.

@JohnnyMorganz
Copy link

Hey folks, just wondering whether there was any movement on this?

I recently stumbled on the exact same issue as in #1223 where we had junit4 tests being run in junit5 without vintage on the classpath, and the tests silently passed with 0 test cases run. Hoping that this could be better reported to the developer if they don't realise their tests didn't actually run

@marcphilipp
Copy link
Member Author

This is definitely on the short list for when I manage to set aside more time for JUnit but nothing concrete has happened, yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests