JUnit Browser Runner

JUnit extension that provides a runner to be used with @RunWith annotation that executes DukeScript tests in a browser.

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

com.dukescript.api
ArtifactId

ArtifactId

junit-browser-runner
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

bundle
Description

Description

JUnit Browser Runner
JUnit extension that provides a runner to be used with @RunWith annotation that executes DukeScript tests in a browser.
Project URL

Project URL

http://dukescript.com
Source Code Management

Source Code Management

https://github.com/dukescript/junit-browser-runner.git

Download junit-browser-runner

Dependencies

compile (3)

Group / Artifact Type Version
com.dukescript.api : junit-osgi jar 4.12
org.netbeans.html : net.java.html jar 1.4
org.netbeans.html : net.java.html.boot jar 1.4

provided (1)

Group / Artifact Type Version
org.apidesign.bck2brwsr : launcher.http jar 0.20

runtime (2)

Group / Artifact Type Version
org.apidesign.bck2brwsr : emul jar 0.20
org.apidesign.bck2brwsr : emul jar 0.20

test (1)

Group / Artifact Type Version
org.netbeans.html : net.java.html.boot.fx jar 1.4

Project Modules

There are no modules declared in this project.

JUnit Browser Runner

JUnit Browser Runner is the easiest way to execute your (not only) DukeScript based code in various testing environments. Simply annotate your test with @RunWith annotation and the runner will handle the rest:

@RunWith(BrowserRunner.class)
public class CodeTest {
  @Test
  public void mathMin() {
    int min = Math.min(3, 5);
    assertEquals("Three is lower", 3, min);
  }
}

The code looks like a regular JUnit testing code - one doesn't have to learn any special concepts. Yet, it is the easiest way to run your tests in browser (without any Java plugin), or test your mixed Java/JavaScript code inside of JavaFX web view or inside of Nashorn scripting engine.

Getting Started

The easiest way to get a working environment is to follow the steps described in the tutorial - e.g. generate the skeletal project from a Maven archetype:

$ mvn archetype:generate \
  -DarchetypeGroupId=com.dukescript.archetype \
  -DarchetypeArtifactId=knockout4j-archetype \
  -DarchetypeVersion=0.13 \
  -Dwebpath=client-web \
  -DgroupId=org.your.test \
  -DartifactId=yesican \
  -Dversion=1.0-SNAPSHOT
$ cd yesican
$ mvn install

The above creates necessary files and executes the client/src/test/java/org/your/test/DataModelTest.java test in a browser. You can edit the file and re-run the tests then.

Configuring

The JUnit Browser Runner is configured via java.util.ServiceLoader mechanism - by including more libraries on classpath of your test, you enable more test runs. That is why you should take a look at your pom.xml file if you want to configure your runner. For example, to enable Nashorn from JDK8 you can add following dependency:

<dependency>
  <groupId>org.netbeans.html</groupId>
  <artifactId>net.java.html.boot.script</artifactId>
  <version>1.4</version>
</dependency>

If you want to run your tests in a JavaFX web view, make sure following dependency is added:

<dependency>
  <groupId>org.netbeans.html</groupId>
  <artifactId>net.java.html.boot.fx</artifactId>
  <version>1.4</version>
</dependency>

and finally, if you include necessary Bck2Brwsr VM libraries, the runner also converts your code to JavaScript and executes it directly in a browser:

<!-- Bck2Brwsr VM presenter for BrowserRunner -->
<dependency>
  <groupId>org.apidesign.bck2brwsr</groupId>
  <artifactId>launcher.http</artifactId>
  <version>0.20</version>
</dependency>
<dependency>
  <groupId>org.apidesign.bck2brwsr</groupId>
  <artifactId>ko-bck2brwsr</artifactId>
  <version>0.20</version>
  <classifier>bck2brwsr</classifier>
</dependency>
<dependency>
    <groupId>com.dukescript.api</groupId>
    <artifactId>junit-browser-runner</artifactId>
    <version>1.0</version>
    <classifier>bck2brwsr</classifier>
</dependency>
<!-- End of Bck2Brwsr VM presenter for BrowserRunner -->

Other implementations of Fn.Presenter are also automatically recognized, so you can include them on the classpath and the runner picks them up.

Versions

Version
1.0
0.9
0.8
0.7
0.6
0.5