-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
ConsoleLauncher returns 0 although selected class could not be loaded #1298
Comments
Thanks for creating the issue! There are use cases when build tools or IDEs pass in test classes and discovering an empty test plan is not considered an error. Do you execute test classes one by one? If so, we could add a |
During the build step we build up a list of a test classes to be executed. During the test step we call You can define the classes / methods to be execute in several ways - looked up by classpath or explicitly specified. From my point of view I consider it an error if the explicitly defined test artifacts cannot be found. This means (IMHO) I would expect a return value != 0 when:
About your suggestion: Possible solutions:
|
Now I'm curious: Why do you build up the list of test classes yourself instead of using JUnit's classpath scanning? |
I think this has historical reasons where Coming back to my suggestion: What return value would you expect when running? For comparison: If you compile unknown class you get return value = 1
Same if you try to delete a non-existing directory or file in Bash ( |
What about extending the proposed Something like: This could be applied to more/all numbers that a gathered by the test execution summary:
Could be guared by the following strict assertions:
|
Thanks @sormuras for your thoughts.
What is the problem if |
I could use |
Remotely related to #542 and marking this issue as "up-for-grabs" too. @pfuerholz or @robstoll or s/o else want to file a PR for an |
Btw. I think you may drop the Jupiter API jar from your command's classpath in the initial issue description. The standalone jar contains it. |
I'm not convinced |
I would say depending on the needs that would suffice and one would increase it from time to time if there are major changes in the discovering mechanism. For instance, if one switches from --scan-classpath to --include-... |
I think |
I'm not convinced that such a use case is all that common. I imagine people would typically implement a custom For your particular use case, you could implement a Another option would be to enable the summary details output of the |
@sbrannen Have you seen my findings (see a few posts above) that if you try to remove a non-existing file or
I would expect return code to be non-zero if class/method/package could not be found! |
No offence, but adding I think we could sanity check selectors and introduce a
etc. @junit-team/junit-lambda Thoughts? |
I think providing such an opt-in feature via an explicit "strict" mode should be fine. |
Personally I would do it the other way round, Be strict and provide an option to be loose. I think it is better to have an aha-junit-has-implement-a-check moment than an aha-junit-does-not-care moment -- well yes, I have chosen biased terms, maybe its just a personal taste, as long as it is documented properly it should not matter. |
Well, that would be a breaking change. So regardless of whether it may be preferential to be strict by default, that ship has already sailed: the JUnit Platform has not performed such a check since its initial release. Consequently, we generally have to err on the side of caution with regard to backwards compatibility. |
unless you declare it as bug in which case you can fix it ;) |
true... but I'm not convinced that it's a 🐛 . |
Tentatively slated for 5.2 M1 for team discussion |
Thanks for taking my point serious! If you change the default behavior or adding a "strict" mode does not matter me. |
Team Decision:
|
Thanks for your information though I am still a bit puzzled by your explanation:
If you wanted let {{--selectClass}} be followed by a JavaScript clause it would be even more helpful to ensure that its evaluation returns a class/method which can be found on the classpath. In the case JUnit shall run JavaScript-code there would still be the case that the code-to-test cannot be found! (Showing an error when the code-to-test cannot be found on the classpath (in Java) or in the filesystem (for JavaScript) would be valid either way...) What you are doing in this case is on you. (We can live with the status quo...) My consideration is that swallowing an error case (here: when not finding the artifact to test) is bad habit. |
No, that was not Marc's point. The topic of this issue is the The The Platform is generic and can support testing frameworks written in various programming languages and test formats. But... somebody could introduce a Third-party test engines already exist for Kotlin, Scala, Groovy, etc. |
When Marc wrote, "but you could use a He could just as easily have said Ruby, Groovy, Kotlin, Scala, or any other language that runs on the JVM. The point is that the Does that make more sense now? 😉 |
When the console launcher found no tests it would succeed. This could happen by user mistake e.g. by improper use of the selector options. In that case due to launcher succeding users would miss the misconfiguration. This option is provided so it can be used to make the launcher fail when no tests are found, helping user's catch such misconfigurations. Fixes: junit-team#1298
When the console launcher found no tests it would succeed. This could happen by user mistake e.g. by improper use of the selector options. In that case due to launcher succeding users would miss the misconfiguration. This option is provided so it can be used to make the launcher fail when no tests are found, helping user's catch such misconfigurations. Fixes: junit-team#1298
When the console launcher found no tests it would succeed. This could happen by user mistake e.g. by improper use of the selector options. In that case due to launcher succeding users would miss the misconfiguration. This option is provided so it can be used to make the launcher fail when no tests are found, helping user's catch such misconfigurations. Fixes: junit-team#1298
When the console launcher found no tests it would succeed. This could happen by user mistake e.g. by improper use of the selector options. In that case due to launcher succeding users would miss the misconfiguration. This option is provided so it can be used to make the launcher fail when no tests are found, helping user's catch such misconfigurations. Fixes: junit-team#1298
When the console launcher found no tests it would succeed. This could happen by user mistake e.g. by improper use of the selector options. In that case due to launcher succeding users would miss the misconfiguration. This option is provided so it can be used to make the launcher fail when no tests are found, helping user's catch such misconfigurations. Fixes: junit-team#1298
When the console launcher found no tests it would succeed. This could happen by user mistake e.g. by improper use of the selector options. In that case due to launcher succeding users would miss the misconfiguration. This option is provided so it can be used to make the launcher fail when no tests are found, helping user's catch such misconfigurations. Fixes: junit-team#1298
…team#1399) Prior to this commit, if the ConsoleLauncher found no tests it would exit with a success status. This could happen by user mistake -- for example, due to improper use of a selector. In such situations, a user would not be informed of the misconfiguration. This commit introduces a new `--fail-if-not-tests` command-line option for the ConsoleLauncher. This flag can be set to `true` to make the launcher fail when no tests are found, helping users catch such misconfigurations. Closes: junit-team#1298
…team#1399) Prior to this commit, if the ConsoleLauncher found no tests it would exit with a success status. This could happen by user mistake -- for example, due to improper use of a selector. In such situations, a user would not be informed of the misconfiguration. This commit introduces a new `--fail-if-not-tests` command-line option for the ConsoleLauncher. This flag can be set to `true` to make the launcher fail when no tests are found, helping users catch such misconfigurations. Closes: junit-team#1298
We run a set of tests in a CI pipeline and call our test classes like this:
If class
xy.Test
cannot be found on the classpath an error message appears butConsoleLauncher
's return value is 0! Since our CI system runs unattended the return value is the only important return value!As I have seen this behaviour got updated in JUnit 5.0.0 M2 but I regard this as a mistake: If I define a class by
--select-class
and the class cannot be found then something has gone wrong!As I countermeasure I hacked (by means of introspection)
org.junit.platform.commons.util.BlacklistedExceptions
by overwriting blacklist's field withOutOfMemoryError
(=default) andPreconditionViolationException
(=case where class could not be found).(If the standard behaviour shall not be changed...) I think there should be a better way to get this behaviour!
(Originates to a post on Stackoverflow.)
The text was updated successfully, but these errors were encountered: