what is required for a class to be found by console launcher? #4764
Replies: 8 comments 19 replies
-
note, one observation is that if I run:
where I basically take the full classpath of genTest.java which includes some of junits own test examples I get:
So it is able to discover test classes...just not the one I want it to discover ;) |
Beta Was this translation helpful? Give feedback.
-
From https://docs.junit.org/current/user-guide/#running-tests-console-launcher-options-discovering-tests
|
Beta Was this translation helpful? Give feedback.
-
What is the exact output of |
Beta Was this translation helpful? Give feedback.
-
Also - if some can make a jar with a test in it that get found by console launcher that would be useful - does not need to have jbang involved i can figure out the delta from there :) |
Beta Was this translation helpful? Give feedback.
-
also - and this is what I don't understand:
aso its not even able to find it when excplictly requested - which is what i find weird as its on the classpath with a jar that has the classes (as far as I can see) |
Beta Was this translation helpful? Give feedback.
-
You wrote that it works with a main method within the test class, right? I guess, that's due to the main (and therefore the test class) is put on the application class loader of the outer What happens, if you move all the |
Beta Was this translation helpful? Give feedback.
-
fyi, made this PR to make this clearer and have a cleaner junit jbang catalog: junit-team/jbang-catalog#1 |
Beta Was this translation helpful? Give feedback.
-
ok so related to this I hit this I still don't grok: Given: ///usr/bin/env jbang "$0" "$@" ; exit $?
package wonka;
//DEPS org.junit.jupiter:junit-jupiter-engine:5.12.2
//DEPS org.junit.platform:junit-platform-console:1.12.2
//DEPS org.assertj:assertj-core:3.27.3
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.junit.platform.console.ConsoleLauncher;
public class consoleTests {
// Define each Unit test here and run them separately in the IDE
@Test
public void testPass() {
assertThat(2+2).isEqualTo(4);
}
@Test
public void testFail() {
assertThat(2+2).isEqualTo(42);
}
// Run all Unit tests with JBang with ./calculator.java
public static void main(final String... args) {
// this finds 2 tests as expected
// commented out because it otherwise calls system.exit(0)
//ConsoleLauncher.main( "discover", "--select-class", "consoleTests");
// package discovery works too
//ConsoleLauncher.main( "discover", "--select-package", "wonka");
// this finds 0 tests - why?
ConsoleLauncher.main( "discover", "--scan-class-path");
}
} why does the explicit selection work but scan class path does not?
why is scan-class-path not finding it? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to figure out why a jar with code like this:
is not found by ConsoleLauncher scan classpath when using it with jbang
While it is picked up if I manually do this:
but i would really just like junit console launcher do it so i dont have to have to carry around the junit test code.
Steps to reproduce:
Install jbang from https://jbang.dev/download or just run
curl -Ls https://sh.jbang.dev | bash -s - app setup
Make a class and a generate junit test suite:
(note: the content of
hello.java
is not relevant; just there to generatehelloTest.java
)Now you have a
hello.java
andhelloTest.java
and you can run the tests using:which will give some output like this:
Showing that the test is runnable - but I really would prefer to not have that
main
method in thehelloTest.java
but rather just run using junit console laucher:
and then just run:
The
jbang info classpath helloTest.java
returns the classpath - you can also just get the jar with no dependenciesjbang info jar helloTest.java
but it seem to make no diff.Also tried adding them in a package (instead of default package)
But consoleLauncher never locates the
helloTest.java
class and I haven't been able to locate why it is not found.Any ideas/suggestions on why they are not found? Whats the magic needed? :)
Beta Was this translation helpful? Give feedback.
All reactions