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

Create "Fat Jar" launcher module: kotest-framework-engine-launcher that can be executed as a process #2416

Closed
GavinRay97 opened this issue Aug 17, 2021 · 16 comments
Assignees
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.
Milestone

Comments

@GavinRay97
Copy link

Following conversation on Slack:

Not sure how much merit this has on it's own, but it would allow Kotest to be integrated into tooling that works with any test framework that provides a runnable binary-ish process consuming options via CLI args (as opposed to build-tool specific integrations).

@GavinRay97 GavinRay97 added the enhancement ✨ Suggestions for adding new features or improving existing ones. label Aug 17, 2021
@jschneidereit jschneidereit self-assigned this Sep 30, 2021
@sksamuel sksamuel assigned sksamuel and unassigned jschneidereit Oct 18, 2021
@sksamuel sksamuel added this to the 5.0 milestone Oct 18, 2021
sksamuel added a commit that referenced this issue Oct 18, 2021
@sksamuel
Copy link
Member

I've added a standalone module. All that's left is to publish it.
@GavinRay97 how would you pass the tests to the instance ?

@GavinRay97
Copy link
Author

GavinRay97 commented Oct 18, 2021

Probably through a small programmatic API that wrapped arguments and then spawned the .jar
Feel like the "safe bet" is for me to copy whatever it is that JUnit does

It's sort of like the saying: "Nobody ever got fired for buying IBM." 😅

$ javac -d out Foo.java 
$ javac -d out -cp out:junit-platform-console-standalone-1.X.X.jar TestClass.java
$ java -jar junit-platform-console-standalone-1.X.X.jar --class-path out --scan-class-path
╷
├─ JUnit Jupiter ✔
│  └─ TestClass ✔
│     └─ test() ✔
└─ JUnit Vintage ✔

Test run finished after 67 ms
Usage: ConsoleLauncher [-h] [--disable-ansi-colors] [--disable-banner]
                       [--fail-if-no-tests] [--scan-modules] [--scan-classpath[=PATH[;|:
                       PATH...]]]... [--details=MODE] [--details-theme=THEME]
                       [--reports-dir=DIR] [-c=CLASS]... [--config=KEY=VALUE]... [-cp=PATH
                       [;|:PATH...]]... [-d=DIR]... [-e=ID]... [-E=ID]...
                       [--exclude-package=PKG]... [-f=FILE]... [--include-package=PKG]...
                       [-m=NAME]... [-n=PATTERN]... [-N=PATTERN]... [-o=NAME]...
                       [-p=PKG]... [-r=RESOURCE]... [-t=TAG]... [-T=TAG]... [-u=URI]...

@sksamuel
Copy link
Member

sksamuel commented Oct 18, 2021 via email

@sksamuel
Copy link
Member

@nikunjy
Copy link
Contributor

nikunjy commented Aug 27, 2022

Hey thanks for writing that @sksamuel
I wrote a test

class SimpleTest: DescribeSpec() {
    init {
        describe("test1") {
            it("testA") {
                val x = 1
                val y = 2
                x + y shouldBe 3
            }
            it("testB") {
                val x = 1
                val y = 2
                x + y shouldNotBe 4
            }
        }

I am able to run this speific package, and class and spec using the launcher. For example I can do

 "--reporter", "teamcity",
                "--package", "com.kotlin.test",
                "--spec", "com.kotlin.test.SimpleTest",
                "--testpath", "test1",

And this works but how can I run the subtest let's say test1/testA. What args should I pass

@sksamuel
Copy link
Member

--testpath test1 -- testA

the -- is our delimiter between nested tests.

@nikunjy
Copy link
Contributor

nikunjy commented Aug 29, 2022

Got it thank you. I am thinking of using this vs the JunitConsoleLauncher
Does it also support pattern matching, I tried something like --testpath test* but it did not work.

@sksamuel
Copy link
Member

not, not wildcard, but it automatically prefixes, so --testpath test would find child tests (but not test2)

@nikunjy
Copy link
Contributor

nikunjy commented Aug 31, 2022

Thanks for the helpful information.
Is it possible to extend this launcher to support patterns like it does with gradle
https://kotest.io/docs/framework/conditional/conditional-tests-with-gradle.html

I am happy to do this PR but does it make sense to do? I think this launcher is better for my purpose because we use bazel plus junit console launcher. We have to write a reporter that bridges the bazel with junit and parse XML etc. However this launcher has a good runner, reporter abstraction and I would rather just use this.

@sksamuel
Copy link
Member

sksamuel commented Sep 1, 2022 via email

@nikunjy
Copy link
Contributor

nikunjy commented Sep 1, 2022

Amazing ! Yes that would work. I would love to use it in a way where I can target the test and the child test. So let's say if we have

class SimpleTest: DescribeSpec() {
    init {
        describe("db simple test") {
            it("insert foo") {
                val x = 1
                val y = 2
                x + y shouldBe 3
            }
            it("delete") {
                val x = 1
                val y = 2
                x + y shouldNotBe 4
            }
        }

      describe("db unique test") {
            it("insert foobar") {
                val x = 1
                val y = 2
                x + y shouldBe 3
            }
            it("delete") {
                val x = 1
                val y = 2
                x + y shouldNotBe 4
            }
        }

       describe("table mine test") {
            it("insert") {
                val x = 1
                val y = 2
                x + y shouldBe 3
            }
            it("delete") {
                val x = 1
                val y = 2
                x + y shouldNotBe 4
            }
        }
}

And then we can do

"--reporter", "teamcity", 
"--package", "com.kotlin.test",
"--spec", "*",
"--testpath", "db*",

Runs all the describes that have word db in it in all the test specs under com.kotlin.test in this case there is only com.kotlin.test.SimpleTest

It is not important if you don't support --testpath in this case imo but it is a good to have.

"--reporter", "teamcity", 
"--package", "com.kotlin.test",
"--spec", "com.kotlin.test.SimpleTest",
"--testpath", "db*",

Runs describe #1 and #2

"--reporter", "teamcity", 
"--package", "com.kotlin.test",
"--spec", "com.kotlin.test.SimpleTest",
"--testpath", "db* -- insertfoo*",

Runs db simple test -- insert foo and db unique test -- insert foobar

@sksamuel
Copy link
Member

sksamuel commented Sep 1, 2022

I think that is fine.

@nikunjy
Copy link
Contributor

nikunjy commented Sep 1, 2022

Updated my comment with the prefix for spec.
Thanks @sksamuel let me know if I can help in some way. It would be pretty awesome to use this :)

@sksamuel
Copy link
Member

sksamuel commented Sep 1, 2022

You could make the PR :)

@nikunjy
Copy link
Contributor

nikunjy commented Sep 1, 2022

@sksamuel Sounds good. I will give it a shot.

@nikunjy
Copy link
Contributor

nikunjy commented Sep 2, 2022

Created an initial PR #3200 @sksamuel

I anticipate it might require revisions. Looking forward to getting a code review :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.
Projects
None yet
Development

No branches or pull requests

4 participants