Unit Testing with jbang #424
Replies: 3 comments 8 replies
-
My thoughts: I don't use a CI server to build my scripts continuously. So when to run the tests? What about linking the test classes in the script file itself? When you run the script the tests are executed first and the script is only executed if the tests pass. You need to add some convenience stuff like caching the results if the class under test did not change or skipping tests explicitly, but this is my first take on this. |
Beta Was this translation helpful? Give feedback.
-
Would also be nice to have a template with unit tests for a JBang script w/ multiple source files as an example. |
Beta Was this translation helpful? Give feedback.
-
Just wondering if there's a current recommendation / best practice regarding this. |
Beta Was this translation helpful? Give feedback.
-
I've been pondering how to go about writing unit tests for jbang scripts/apps.
There are two parts afaics, one on how the tests look like the other how to run them.
The first part on how they look like I think is fairly straight forward now we have
//SOURCES
feature.i.e. if you have script looking like:
Then the most basic test of that would be:
This setup actually works (kinda) today and you can use idea with
jbang edit TestLauncher
and you can run the tests just fine directly from the ide.I'm wondering how/if we should add some native test support to
jbang
to make it easier.i.e.
jbang unittest TestLauncher.java
could generate what corresponds to:jbang org.junit.platform:junit-platform-console-standalone:1.7.0 --classpath 'jbang info classpath testscript.java' --scan-classpath
where
jbang info classpath
generates the classpath.then junit 5 test runner would find all identifiable tests and run them.
Could also just tell users to run the above command but a) its quite long and b) it won't work on windows.
Ideas/thoughts on testing with jbang?
Beta Was this translation helpful? Give feedback.
All reactions