• Stars
    star
    132
  • Rank 269,481 (Top 6 %)
  • Language
    Java
  • License
    BSD 2-Clause "Sim...
  • Created over 14 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implementation of sbt's test interface for JUnit

JUnit Interface

JUnit Interface is an implementation of sbt's test interface for JUnit 4. This allows you to run JUnit tests from sbt. For JUnit 5, check out maichler/sbt-jupiter-interface.

Unlike Scala testing frameworks like ScalaTest (which can also run JUnit test cases), both JUnit and this adapter are pure Java, so you can run JUnit tests with any Scala version supported by sbt without having to build a binary-compatible test framework first.

Setup

Add the following dependency to your build.sbt:

libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.2" % Test

Note: Organization name has changed to "com.github.sbt" in 0.12.

JUnit itself is automatically pulled in as a transitive dependency.

junit-interface version JUnit version
0.13.2 4.13.2
0.13.1 4.13.1
0.13 4.13
0.12 4.12

sbt already knows about junit-interface so the dependency alone is enough. You do not have to add it to the list of test frameworks.

Usage

To run the JUnit tests, type in test in the sbt shell:

> test

To run the tests incrementally, and run only the failed tests since the last run, type in testQuick:

> testQuick

To run only a specific test suite, use testOnly <class name glob>:

> testOnly example.HelloTest

You can use a glob pattern instead as:

> testOnly *.HelloTest

To run only a specific test example (a method) within a test suite, use testOnly -- <test name>:

> testOnly -- example.HelloTest.testSuccess1
print from testSuccess1
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1

You can use the glob pattern here as well:

> testOnly -- *.HelloTest.testI*
[info] Test example.HelloTest.testIgnored1 ignored
[info] Test example.HelloTest.testIgnored2 ignored
[info] Test example.HelloTest.testIgnored3 ignored

Note: Any arguments after -- are treated as test framework argument, and they are passed to junit-interface. Because test task cannot take any arguments, we can use testOnly task to pass ad-hoc options.

To get run all tests with verbose output:

> testOnly -- -v
print from testSuccess1
[info] Test run example.HelloTest started
[info] Test example.HelloTest.testSuccess1 started
[info] Test example.HelloTest.testIgnored1 ignored
[info] Test example.HelloTest.testIgnored2 ignored
[info] Test example.HelloTest.testIgnored3 ignored
[info] Test run example.HelloTest finished: 0 failed, 3 ignored, 1 total, 0.005s
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1, Ignored 3

The following options are supported for JUnit tests:

Option Description
-v Same as --verbosity=2
-q Suppress stdout for successful tests. Stderr is printed to the console normally. Stdout is written to a buffer and discarded when a test succeeds. If it fails, the buffer is dumped to the console. Since stdio redirection in Java is a bad kludge (System.setOut() changes the static final field System.out through native code) this may not work for all scenarios. Scala has its own console with a sane redirection feature. If Scala is detected on the class path, junit-interface tries to reroute scala.Console's stdout, too.
-n Do not use ANSI colors in the output even if sbt reports that they are supported.
-s Try to decode Scala names in stack traces and test names. Fall back silently to non-decoded names if no matching Scala library is on the class path.
-a Show stack traces and exception class name for AssertionErrors (thrown by all assert* methods in JUnit).`
-c Do not print the exception class name prefix for any messages. With this option, only the result of getMessage() plus a stack trace is shown.
+v Same as --verbosity=0
+q Turn off -q. Takes precedence over -q.
+n Turn off -n. Takes precedence over -n.
+s Turn off -s. Takes precedence over -s.
+a Turn off -a. Takes precedence over -a.
+c Turn off -c. Takes precedence over -c.
--ignore-runners=<COMMA-SEPARATED-STRINGS> Ignore tests with a @RunWith annotation if the Runner class name is contained in this list. The default value is org.junit.runners.Suite.
--tests=<REGEXPS> Run only the tests whose names match one of the specified regular expressions (in a comma-separated list). Non-matched tests are ignored. Only individual test case names are matched, not test classes. Example: For test MyClassTest.testBasic() only "testBasic" is matched. Use sbt's testOnly task instead to match test classes.
-Dkey=value Temporarily set a system property for the duration of the test run. The property is restored to its previous value after the test has ended. Note that system properties are global to the entire JVM and they can be modified in a non-transactional way, so you should run tests serially and not perform any other tasks in parallel which depend on the modified property.
--run-listener=<CLASS_NAME> A (user defined) class which extends org.junit.runner.notification.RunListener. An instance of this class is created and added to the JUnit Runner, so that it will receive the run events. For more information, see RunListener. Note: this uses the test-classloader, so the class needs to be defined in src/test or src/main or included as a test or compile dependency
--include-categories=<CLASSES> A comma separated list of category class names that should be included. Only tests with one or more of these categories will be run.
--exclude-categories=<CLASSES> A comma separated list of category class names that should be excluded. No tests that match one or more of these categories will be run.
--verbosity=<INT> Higher verbosity logs more events at level "info" instead of "debug". 0: Default; 1: "Test run finished" at info; 2: Also "test run started" and "test started" at info; 3: Also "test finished" at info.
--summary=<INT> The type of summary to show for a test task execution. 0: Leave to sbt (default); 1: One line; 2: Include list of failed tests

Any parameter not starting with - or + is treated as a glob pattern for matching tests. Unlike the patterns given directly to sbt's testOnly task, the patterns given to junit-interface will match against the full test names (as displayed by junit-interface) of all atomic test cases, so you can match on test methods and parts of suites with custom runners.

You can set default options in your build.sbt file:

testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v")

Or use them with the testQuick and testOnly commands:

> testOnly -- +q +v *Sequence*h2mem*

Credits

  • junit-interface was created by Stefan Zeiger @szeiger in 2009
  • See contributors for the list of other contributors

License

See LICENSE.txt for licensing conditions (BSD-style).

More Repositories

1

sbt

sbt, the interactive build tool
Scala
4,685
star
2

sbt-native-packager

sbt Native Packager
Scala
1,590
star
3

sbt-dependency-graph

sbt plugin to create a dependency graph for your project
Scala
1,241
star
4

sbt-jmh

"Trust no one, bench everything." - sbt plugin for JMH (Java Microbenchmark Harness)
Scala
783
star
5

sbt-eclipse

Plugin for sbt to create Eclipse project definitions
Scala
719
star
6

sbt-release

A release plugin for sbt
Scala
640
star
7

sbt-buildinfo

I know this because build.sbt knows this.
Scala
546
star
8

sbt-web

Library for building sbt plugins for the web
Scala
366
star
9

sbt-git

A git plugin for sbt
Scala
343
star
10

zinc

Scala incremental compiler library, used by sbt and other build tools
Scala
328
star
11

docker-sbt

Official sbt docker images
Dockerfile
313
star
12

sbt-dynver

An sbt plugin to dynamically set your version from git
Scala
297
star
13

sbt-ci-release

sbt plugin to automate Sonatype releases from GitHub Actions
Scala
278
star
14

sbt-onejar

Packages your project using One-JAR™
Scala
267
star
15

sbt-scalariform

sbt plugin adding support for source code formatting using Scalariform
Scala
258
star
16

sbt-fresh

sbt-plugin to create an opinionated fresh sbt project
Scala
233
star
17

sbt-github-actions

An sbt plugin which makes it easier to build with GitHub Actions
Scala
194
star
18

sbt-header

sbt-header is an sbt plugin for creating file headers, e.g. copyright headers
Scala
186
star
19

sbt-bintray

fresh packages delivered from your sbt console
Scala
179
star
20

sbt-protobuf

sbt plugin for compiling protobuf files
Scala
174
star
21

sbt-site

Site generation for sbt
Scala
173
star
22

sbt-start-script

SBT Plugin to create a "start" script to run the program
Scala
144
star
23

sbt-pgp

PGP plugin for sbt
Scala
141
star
24

sbt-groll

sbt plugin to roll the Git history
Scala
133
star
25

sbt-unidoc

sbt plugin to create a unified Scaladoc or Javadoc API document across multiple subprojects.
Scala
124
star
26

sbt-jni

SBT Plugin to ease working with JNI
Scala
123
star
27

sbt-jacoco

an sbt plugin for JaCoCo Code Coverage
Scala
123
star
28

sbt-projectmatrix

Scala
118
star
29

sbt-boilerplate

sbt plugin for generating scala.Tuple/Function related boilerplate code
Scala
109
star
30

sbt-proguard

Proguard sbt plugin
Scala
98
star
31

sbt-atmos

sbt plugin for running Typesafe Console in development
Scala
98
star
32

sbt-launcher-package

Packaging for sbt so you can run it.
Scala
89
star
33

sbt-dirty-money

clean Ivy2 cache
Scala
88
star
34

sbt-license-report

Report on licenses used in an sbt project.
Scala
86
star
35

website

The source for scala-sbt.org
Scala
77
star
36

sbt-doge

sbt plugin to aggregate tasks across subprojects and their crossScalaVersions
Scala
77
star
37

sbt-pom-reader

Translates xml -> awesome. Maven-ish support for sbt.
Scala
76
star
38

sbt-remote-control

Create and manage sbt process using unicorns and forks
Scala
74
star
39

sbt-aspectj

AspectJ sbt plugin
Scala
72
star
40

sbt-scalabuff

SBT plugin which generate case classes and support for serialization from Google Protocol Buffer definitions using ScalaBuff
Scala
72
star
41

contraband

http://www.scala-sbt.org/contraband/
Scala
67
star
42

sbt-s3

sbt-s3 is a simple sbt plugin to manipulate objects on Amazon S3
Scala
63
star
43

sbt-multi-jvm

Multi-JVM testing in sbt
Scala
56
star
44

sbt-javaagent

sbt plugin for adding java agents to projects
Scala
53
star
45

sbt-paradox-material-theme

Material Design theme for Paradox
StringTemplate
51
star
46

sbt-cpd

Copy & Paste Detector plugin using PMD for sbt.
Scala
48
star
47

sbt-osgi

sbt plugin for creating OSGi bundles
Scala
47
star
48

sbt-man

Looks up scaladoc.
Scala
46
star
49

sbt-findbugs

FindBugs static analysis plugin for sbt.
Scala
46
star
50

librarymanagement

librarymanagement module for sbt
Scala
44
star
51

sbt-less

Scala
42
star
52

ipcsocket

IPC: Unix Domain Socket and Windows Named Pipes for Java
Java
42
star
53

launcher

The sbt launcher as its own project. Can launch any ivy/maven published project with a main class, with some fancy features.
Scala
41
star
54

io

IO module for sbt
Scala
40
star
55

sbt-js-engine

Support for sbt plugins that use JavaScript
Scala
40
star
56

sbt-autoversion

Scala
36
star
57

sbt-avro

sbt plugin for compiling Avro schemas, similar to sbt-protobuf
Scala
32
star
58

sbt-digest

sbt-web plugin for checksum files
Scala
32
star
59

sbt-jupiter-interface

Implementation of SBT's test interface for JUnit Jupiter
Java
31
star
60

sbt-slash

unified slash syntax for both shell and build.sbt
Scala
29
star
61

sbt-java-formatter

An sbt plugin for formating Java code
Scala
28
star
62

sbt-gzip

sbt-web plugin for gzipping assets
Scala
25
star
63

sbt-unique-version

emulates Maven's uniqueVersion snapshots
Scala
24
star
64

sbt-pull-request-validator

Plugin that optimizes pull request validation to only validate sub projects that have changed
Scala
24
star
65

sbt.github.com

See https://github.com/sbt/website for the source
HTML
22
star
66

sbt-duplicates-finder

Find classes and resources conflicts in your build
Scala
22
star
67

sbt-autoplugin.g8

giter8 template for sbt 0.13.5+ AutoPlugin
Scala
20
star
68

sbt-cucumber

Cucumber plugin for SBT.
Scala
20
star
69

sbt-jcstress

Trust no-one, and especially not memory visibility.
HTML
19
star
70

adept

adept helps you find, declare, and download dependencies. http://groups.google.com/group/adept-dev/
18
star
71

sbt-sriracha

Scala
17
star
72

sbt-mocha

SBT plugin for running mocha JavaScript unit tests on node
Scala
17
star
73

sbt-multi-release-jar

Support for JDK9's Multi Release JAR Files (JEP 238)
Scala
17
star
74

sbt-xjc

SBT plugin to compile an XML Schema with XJC
Scala
15
star
75

util

util modules for sbt
Scala
15
star
76

sbt-export-repo

exports your dependency graph to a preloaded local repository
Scala
15
star
77

sbt-nocomma

sbt-nocomma reduces commas from your build.sbt.
Scala
13
star
78

serialization

serialization facility for sbt
Scala
13
star
79

sbt-maven-resolver

An sbt plugin to resolve dependencies using Aether
Scala
12
star
80

sbt-core-next

sbt APIs targeted for eventual inclusion in sbt core
Scala
12
star
81

sbt-houserules

House rules for sbt modules.
Scala
12
star
82

sbt-pamflet

sbt plugin to run Pamflet (and Pamflet plugin to run sbt)
Scala
11
star
83

sbt-sdlc

Scaladoc link checker for sbt
Scala
11
star
84

sbt-appbundle

A plugin for the simple-build-tool to create an OS X application bundle.
Scala
10
star
85

bintry

your packages, delivered fresh
Scala
10
star
86

sbt-fmpp

FreeMarker Scala/Java Templating Plugin for SBT
Scala
9
star
87

sbt-ynolub

Scala
9
star
88

sbt-testng

Implementation of the sbt testing interface for TestNG, bundled with an sbt plug-in for convenience.
Scala
9
star
89

sbt-concat

sbt-web plugin for concatenating web assets
Scala
8
star
90

sbt-ant

SBT plug-in to call Ant targets from within SBT builds
Scala
7
star
91

sbtn-dist

Shell
6
star
92

sbt-community-plugins

All community plugins that opt into an uber-build
Scala
6
star
93

sbt-vimquit

an sbt plugin that adds :q command.
Scala
5
star
94

helloworld-one

An example build for sbt 1.0.0.
Scala
5
star
95

sbt-giter8-resolver

Scala
5
star
96

sbt-sequential

adds sequential tasks to sbt
Scala
4
star
97

sbt-scalashim

generates sys.error.
Scala
4
star
98

sbt-experimental

Experimental APIs to fix rough edges in sbt
Scala
3
star
99

sbt-web-build-base

Scala
3
star
100

sbt-validator

Builds sbt 1.0.x against recent versions of the sbt modules
Shell
3
star