Skip to content

junit-team/jbang-catalog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 

Repository files navigation

JUnit JBang Catalog

This catalog provides easy access to the JUnit Platform Console Standalone via JBang, making it simple to run JUnit tests from the command line or as a JBang-installed app.

Quick Start

To use JUnit with JBang, first ensure you have JBang installed.

Run the JUnit Platform Console Standalone directly:

jbang junit@junit-team

Or install it as a command for easier reuse:

jbang app install junit@junit-team
junit

Running Tests

To run JUnit tests, provide your test classpath and scan for tests:

junit --class-path <your classpath with tests included> --scan-classpath

If your tests are packaged in a Maven artifact, you can use JBang to resolve the classpath:

junit --class-path `jbang info classpath org.your:app:1.2.3` --scan-classpath

Replace org.your:app:1.2.3 with your actual Maven coordinates.

Advanced Usage

Using a Specific Java Version

You can specify a Java version when running or installing:

jbang --java 25 junit@junit-team --class-path <your classpath> --scan-classpath

Or when installing:

jbang app install --java 25 junit@junit-team

Using a Specific Version of JUnit

To use a specific version of the JUnit CLI, you can run it directly with Maven coordinates:

jbang org.junit.platform:junit-platform-console-standalone:1.13.3

JBang Script Tests

JBang provides a JUnit template to help you create and run tests for JBang scripts.

  1. Create a script:
    jbang init helloworld.java
  2. Create a test for it:
    jbang init -t junit@jbangdev helloworld.java
    This generates helloworldTest.java that includes helloworld.java for easy test setup.
  3. Build the test:
    jbang build helloworldTest.java
  4. Run the test:
    junit --class-path `jbang info classpath helloworldTest.java` --scan-classpath

Example output (with a failing test):

💚 Thanks for using JUnit! Support its development at https://junit.org/sponsoring

╷
├─ JUnit Platform Suite ✔
├─ JUnit Jupiter ✔
│  └─ helloworldTest ✔
│     └─ testhelloworld() ✘ You should add some testing code for helloworld here! ==> expected: <1> but was: <2>
└─ JUnit Vintage ✔

Failures (1):
  JUnit Jupiter:helloworldTest:testhelloworld()
    MethodSource [className = 'helloworldTest', methodName = 'testhelloworld', methodParameterTypes = '']
    => org.opentest4j.AssertionFailedError: You should add some testing code for gen here! ==> expected: <1> but was: <2>
       org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
       org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
       org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
       org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
       org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:563)
       helloworldTest.testhelloworld(helloworldTest.java:27)
       java.base/java.lang.reflect.Method.invoke(Method.java:580)
       java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
       java.base/java.util.ArrayList.forEach(ArrayList.java:1597)

Test run finished after 35 ms
[         4 containers found      ]
[         0 containers skipped    ]
[         4 containers started    ]
[         0 containers aborted    ]
[         4 containers successful ]
[         0 containers failed     ]
[         1 tests found           ]
[         0 tests skipped         ]
[         1 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         1 tests failed          ]

Additional Help

You can run junit and get command line help or read the User Guide

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •