Giter Club home page Giter Club logo

junit-interface's Introduction

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).

junit-interface's People

Contributors

ashawley avatar benmccann avatar bijukunjummen avatar dwijnand avatar ebuchanan avatar eed3si9n avatar havocp avatar jroper avatar jsuereth avatar matthewfarwell avatar megazord avatar rjmac avatar sdb avatar shinichy avatar szeiger avatar unkarjedy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

junit-interface's Issues

SBT 1.3. and junit-interface 0.11 not running JUnit tests

This is just meant to be a duplicate of #35 but for SBT 1.3, and putting SBT 1.3 in the title of the issue to help anyone searching on the web for a solution.

I came across #35 while trying to understand why my JUnit tests stopped running when I moved from SBT 1.2.8 to 1.3.13 (both with junit-interface 0.11).

Basically the same crossPaths := false solution from #35 works in the case of SBT 1.3.

--include/exclude-categories ignored

As far as I can tell, neither --include-categories= nor --include-categories= do anything. Given e.g.

@org.junit.experimental.categories.Category(com.example.FastTests.class)
public class ExampleTest {
  @org.junit.Test
  public void test() {
    ...
  }
}

...both test-only -- -v --include-categories=com.example.FastTests and test-only -- -v --exclude-categories=com.example.FastTests run all tests.

sbt 0.13.1 and junit-interface 0.10 doesn't run JUnit tests

I have a project where we have lots of unit tests written. We've recently upgraded to sbt 0.13 and now our unit tests don't run. If I add the following to my build.sbt:

crossPaths := false

then it picks up the tests and runs successfully.

I built my own version of the plug-in and put in some debugging statements and then turned on global debugging within the build.sbt and it appears that the JUnitRunner is never even instantiated when crossPaths is defaulted to true.

-q option behaves very badly

This bug was originally filed with SBT and was tracked down to being an issue in junit-interface.

The -q option makes the SBT console disappear. I've created a repository that reproduces this bug.

The console prompt should reappear when the tests have finished running:

[success] Total time: 0 s, completed Oct 30, 2014 5:34:15 PM
>

However, due to this bug, often times you won't see the prompt appear after the tests have run:

[success] Total time: 0 s, completed Oct 30, 2014 5:41:37 PM

This is super annoying because it was happening to me nearly every time I run my tests making me constantly kill and restart the SBT console. It happens much less with the sample repository than my real project (I'm guessing because there are fewer tests so I hit whatever race condition less often). I added the -q option following a suggestion from @jroper on the Play mailing list and not really examining what the option does. When I try it now I find that I can see absolutely no difference in the output with the option on or off and so the option seems to be rather broken as it is having no effect.

@retronym suggested the following:

At a minimum, it would be good to detect when it is being used in a parallel test run and try to fail fast.

I suppose junit-interface could to install a custom OutputStream that multiplexes across a ThreadLocal[OutputStream]. The test started event could increment an AtomicInteger counter, test finished would decrement. When the counter goes from 0 -> 1, this multiplexing stream would be installed as System.out, conversely when it goes from 1 -> 0 the original could be restored.

Googling ThreadLocalOutputStream yields a similar approach taken in startup-java-fast.

specs2 tests with @RunWith annotations execute twice

I'm not even certain that this is a bug in junit-interface; please shoot me down if you feel this issue should be logged somewhere else.

I've got a handful of Play projects with specs2 tests that subclass SpecificationWithJUnit and have @RunWith annotations. In older versions of Play (depended on junit-interface 0.8) these tests executed as expected. With the latest version of Play (depends on junit-interface 0.9) I'm seeing all of my tests execute twice.

If I remove the @RunWith annotations, the problem goes away. Removing these annotations prevents our tests from being executable within Eclipse, though.

I can work around this by pulling in 0.10-M2 and using --ignore-runners=org.specs2.runner.JUnitRunner, but this feels like a hack. Do you consider the double test execution a regression in junit-interface, or a bug in Play?

Conflict with Specs2 when ignoring @RunWith tests

In Play we have a problem with Specs2 tests not being picked up by SBT. Whether tests pass or fail, SBT reports that no tests were run:

[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[success] Total time: 8 s, completed 22/10/2013 6:08:09 PM

I created a small SBT application, captured in this gist, that reproduces the problem. The problem occurs when all three of the following are present:

  • tests are forked
  • the specs2 test has @RunWith(classOf[JUnitRunner])
  • the JUnit interface is given the argument --ignore-runners=org.specs2.runner.JUnitRunner

We can work around the problem by changing the order of testFrameworks so that Specs2 runs before JUnit. This is our solution for now.

But this solution is fragile and it would be great to fix the underlying problem. I've talked with @harrah, and he thinks that the underlying issue is in junit-interface, probably the same issue as reported in #21.

Publish a new release of junit-interface?

junit-interface 0.11 was released over 6 years ago. Since then, various improvements have been pushed to this repo including 2018357 last year which provides some nice improvements to the test output. Would it be possible to publish a new release to maven?

Spring @ContextConfiguration problem

Hi,

I am using sbt + spring + junit-interface.
I have an issue with @ContextConfiguration, it desn't load configuration file automatically.

Snippet from the Spring documentation:

package com.example;

@RunWith(SpringJUnit4ClassRunner.class)
// ApplicationContext will be loaded from "classpath:/com/example/MyTest-context.xml"
@ContextConfiguration
public class MyTest {
    // class body...
}

Instead of automatically loaded ApplicationContext I get FileNotFoundException:

...nested exception is java.io.FileNotFoundException: class path resource [com/test/app/AppTest-context.xml] cannot be opened because it does not exist

The test class and configuration file is located in the same directory e.g., AppTest.scala and AppTest-context.xml

Adding full path to configuration file solve the problem

@RunWith(classOf[SpringJUnit4ClassRunner])
@ContextConfiguration(Array("file:src/test/scala/com/test/app/AppTest-context.xml"))

Is this junit-interface issue?

Best,
Krzysiek
@kgrodzicki

(It is not a test) tests reported

related to the test reporting that was implemented for #48

I see a lot of these reported in Jenkins where my specs2 tests are reported by the junit reporter

<testcase classname="xx.xxx.FooSpec" name="(It is not a test)" time="-0.001"></testcase>

So the reporting is not skipping files that are not JUnit test files

The stack trace of a failed assertThat always shows only hamcrest line.

When assertThat statement fails, the stack trace always shows "at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)".
I'd like it to show "com.shinichy.convertBox.test.MainActivityTest.checkViews(MainActivityTest.scala:41)" line.

The stack trace is below.

org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
org.junit.Assert.assertThat(Assert.java:865)
com.shinichy.convertBox.test.MainActivityTest.checkViews(MainActivityTest.scala:41)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
...

I confirmed this on JUnit 4.11 + junit-interface 0.9.

0.11-RC1 Test report contains wrong stacktrace/message on fork

This is what is reported in the junit xml reports

sbt.ForkMain$ForkError
    at com.xxx.ServerTest.testInjectingRawData(ServerTest.java:573)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

But the actual failing test stacktrace looks like this

[error] Test com.xxx.ServerTest.testInjectingRawData failed: java.lang.NullPointerException: null, took 0.118 sec
[error]     at com.xxx.ServerTest.testInjectingRawData(ServerTest.java:573)
[error]     ...

running tests against exportJar never close the file handlers

On Windows, if you open a file handle, you can never modify / delete / move that file until the file handle is given up.

Unfortunately, the java.util.jar.JarFile API is a big offender and creates a file handle on creation. It only gives up the handle if close() is called directly or via finalize().

If sbt is set up to use exportJars, and junit-interface is used (I've confirmed and isolated that the junit-interface must be present to trigger this bug), JarFile references are not closed and - for some inexplicable reason - forcing gc and runFinalizers doesn't trigger the finalizers to run (this is a well known "feature" of Java), as per sbt/sbt#1223 which seems to workaround similar bugs in the scala compiler itself, see https://issues.scala-lang.org/browse/SI-9632 and https://github.com/ensime/ensime-server/issues/1322 (I'll give this an SI- soon).

Unfortunately, this is quite a serious bug.

It has the unfortunate side effect that the build tool can no longer delete any of the jars and compilation effectively becomes a no-op. I believe sbt may silently fail at this point, but I'm using some extremely loud customisations that check for failure https://github.com/fommil/sbt-big-project/blob/master/src/main/scala/BigProjectSettings.scala#L104

Others may have experienced this but it would have manifested itself in terms of the jar file not being updated.

In case it is relevant (I'm not sure it is), my project uses junit 4.11.0 and I depend on junit-interface intransitively.

Memory Leak in regard to TestClassLoader / Metaspace

At the moment, https://github.com/sbt/junit-interface/blob/master/src/main/java/com/novocode/junit/JUnitRunner.java#L123 loads all the test classes in the same classloader.
Depending on the amount of tests, this becomes a problem, because class definitions get loaded multiple times, but are not garbage collected.

At my current project, this leads to Out of memory: Metaspace exceptions after a few tests.

I think it would be good if we could create a child classloader for every TestClass which we throw away after the tests ran.

What do you think?

Doesn't support scala 2.11

build.sbt libraryDependencies

  "com.novocode" %% "junit-interface" % "0.11" % "test"
[error] (*:update) sbt.ResolveException: unresolved dependency: com.novocode#junit-interface_2.11;0.11: not found

SBT is not finding JUnit tests

My build.sbt specifies the junit plugin:

libraryDependencies in ThisBuild += "com.novocode" % "junit-interface" % "0.10-M4" % "test"

The project has plenty of Java junit tests in the default {proj}/src/test/java that run fine when I use my Maven build.

Why would SBT not see my junit tests? Is there any way I can debug this?

The output I get:

[info] Loading global plugins from /home/devuser/.sbt/0.13.0-Beta2/plugins
[info] Set current project to myproj (in build file:/home/devuser/src/myproj/)
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[info] No tests to run for myproj/test:test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[info] No tests to run for myproj-subproja/test:test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[info] No tests to run for myproj-subprojb/test:test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[info] No tests to run for myproj-subprojc/test:test
[success] Total time: 0 s, completed Jun 23, 2013 8:01:41 AM

No tests to run for test:test

Hi,

I'm using this to write my junit4 tests.
The test files are in src/test/java/.... but when I run "sbt test" I get "No tests to run for test:test".

How do I let sbt know that these tests exist?

Thanks!

@RunWith does not work

I'm trying to run a test suite in Play Framework. I've upgraded Play locally to use junit-interface 0.10-M1, but @RunWith is still having no effect. I would expect my println to be visible on the console when running the tests.

package com.benmccann;

import junit.framework.TestSuite;

import org.junit.runner.RunWith;
import org.junit.runners.AllTests;

@RunWith(AllTests.class)
public class AllTestsSuite {

  public static junit.framework.Test suite() {
System.out.println("\n\nWHY ISN'T THIS METHOD BEING CALLED?\n\n");
    return new TestSuite();
  }

}

JUnit interface seems not to find all JUnit tests written in Scala

I have a rather big Scala project with JUnit tests written in Scala which I used to build with Maven but I thought I would give SBT a trie. Sadly the JUnit interface doesn't seem to find any of the more involved tests in the src/test/scala folder. Even though they are compiled properly. I thought it could have something to do with the fact that I use the @BeforeClass annotation in the companion object of the individual tests.

I couldn't reproduce the exact problem with a minimal example. In the example I came up with sbt seems to generate a random number X for the line.

[info] Passed: : Total X, Failed 0, Errors 0, Passed X, Skipped 0

Even though all tests produce output.

Here's the setup and output:

./build.sbt

name := "sbt junit test project"

version := "1.0"

scalaVersion := "2.9.1"

libraryDependencies += "com.novocode" % "junit-interface" % "0.8" % "test"

./src/test/scala/Test1.scala

import org.junit.Test
class Test1 {
  @Test
  def test1 {
    println ("Test1.test1 is here!")
  }
}

./src/test/scala/Test2.scala

import org.junit.Test
import org.junit.BeforeClass
object Test2 {
  var x = 0
  @BeforeClass 
  def setUp {
    x = 42
  }
}
class Test2 {
  @Test
  def test2 {
    println ("Test2.test2 is here!")
  }
}

./src/test/scala/org/bla/blub/Test3.scala

package org.bla.blub
import org.junit.Test
import org.junit.BeforeClass
object Test3 {
  var x = 0
  @BeforeClass 
  def setUp {
    x = 42
  }
}
class Test3 {
  @Test
  def test3 {
    println ("Test3.test3 is here!")
  }
}

And here is the output sbt produces when running test

$ sbt
[info] Set current project to sbt junit test project (in build file:/Users/bnord/tests/sbttest/)
> test
[info] Updating {file:/Users/bnord/tests/sbttest/}default-e153b9...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving com.novocode#junit-interface;0.8 ...
[info] Resolving junit#junit;4.8.2 ...
[info] Resolving org.scala-tools.testing#test-interface;0.5 ...
[info] Done updating.
Test3.test3 is here!
Test2.test2 is here!
Test1.test1 is here!
[info] Passed: : Total 3, Failed 0, Errors 0, Passed 3, Skipped 0
[success] Total time: 1 s, completed 22.02.2012 11:34:15
> test
Test1.test1 is here!
Test3.test3 is here!
Test2.test2 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:17
> test
Test3.test3 is here!
Test1.test1 is here!
Test2.test2 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:19
> test
Test1.test1 is here!
Test2.test2 is here!
Test3.test3 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:20
> test
Test3.test3 is here!
Test2.test2 is here!
Test1.test1 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:21
> test
Test3.test3 is here!
Test2.test2 is here!
Test1.test1 is here!
[info] Passed: : Total 1, Failed 0, Errors 0, Passed 1, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:23
> test
Test3.test3 is here!
Test1.test1 is here!
Test2.test2 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:27

Support for @RunWith

I'm trying to use cucumber-jvm with SBT, and it would be great if this tool could support @RunWith

package cucumber.examples.scalacalculator

import org.junit.runner.RunWith
import org.junit.Test
import cucumber.junit.Cucumber

@RunWith(classOf[Cucumber])
class RunCukesTest {

}

only is detected if you annotate it with @test above @RunWith - but then it doesn't return correctly after executing the Cucumber tests.

Create better test summary

Right now, it just lists the class that had a failing test eventhough there are several tests in that class. It would be much more helpful if it listed the failed method names as well.

[error] Failed: Total 293, Failed 1, Errors 0, Passed 280, Skipped 12
[error] Failed tests:
[error]         com.connectifier.MyTest

This is the built-in, default summary from sbt. It is a generic summary that supports all frameworks and thus doesn't try to be too fancy. In the new test interface supported by 0.13, test frameworks can provide their own summary that will override sbt's.

https://github.com/sbt/test-interface/blob/master/src/main/java/sbt/testing/Runner.java#L87

JUnit Tests Ignored when Forking is Enabled

I have a Java project that I'm building with SBT. The only Scala code is in the tests.
I need to run some slow tests in a separate process, with a high memory option (-Xmx).
I want to do that using forking. However, this does not work, as JUnit tests are ignored.

This is an excerpt of my build.sbt:

crossPaths := false
scalaVersion := "2.12.4"
autoScalaLibrary := false
sbtVersion := "1.1.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.3" % "test"
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.5" % "test"
libraryDependencies += "junit" % "junit" % "4.12" % "test"
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q")
Test / parallelExecution := false

This configuration makes my jUnit tests run when I do sbt test.
If I add fork in Test := true, then only my ScalaTest tests execute.

class name is not Scala-ified in the "Failed tests:" part of the report

Version: 0.10-M4
Options passed in: testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-s")

Reproducible by:

package test

import org.junit.Assert._
import org.junit.{ Test => T}

class Foo should be {
val isCool = false
@t def cool { assert(isCool) }
@t def nonEmpty { assert(true) }
@t def badass { assert(false) }
@t def hakker { assert(true) }
}

Output:

[info] Test test.Foo should be.nonEmpty started
[info] Test test.Foo should be.cool started
[error] Test test.Foo should be.cool failed: assertion failed
[info] Test test.Foo should be.hakker started
[info] Test test.Foo should be.badass started
[error] Test test.Foo should be.badass failed: assertion failed
[info] Test run finished: 2 failed, 0 ignored, 4 total, 0.008s
[error] Failed: : Total 4, Failed 2, Errors 0, Passed 2, Skipped 0
[error] Failed tests:
[error] test.Foo$u0020should$u0020be <<----------------- OFFENDING LINE
[trace] Stack trace suppressed: run last test:test for the full output.
error Tests unsuccessful
[error] Total time: 1 s, completed Jul 3, 2013 2:10:00 AM

Reporting tests as skipped instead of ignored

Shouldn't this be Status.Ignored instead of Status.Skipped in EventDispatcher.java? I'm not really sure when you'd report a test as skipped, but I'd imagine if you mark a test with @Ignore then it should be reported as ignored instead of skipped given that a Status exists for both of those

@Override
public void testIgnored(Description desc)
{
  postIfFirst(new InfoEvent(desc, Status.Skipped) {
    void logTo(RichLogger logger) {
      logger.info("Test "+ansiName+" ignored");
    }
  });
}

0.10 final release

Please release 0.10 final as 0.10-M4 has been out there for 3 months.

Thanks.

Better detection of illegal options

Currently any non-option parameter is treated as a glob pattern which can lead to surprising bugs. For example, see https://gist.github.com/ktoso/baba2cacad58bddd4235 which is caused by "testOptions in Test += Tests.Argument("-oDF")" (parameters for ScalaTest which are not scoped correctly). Since glob patterns starting with a dash should be rare, I suggest we require an extra "--" separator before any such options, e.g. "test-only -- -v -a -- -reallyAPattern". Any other argument starting with a dash before this separator should be reported as an error and fail the whole test run.

Tests annotated using @RunWith not picked up by sbt

This test is not picked up:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-context.xml"})
public class MyTest {

but if @RunWith is commented out the test is picked up (but obviously does not work correctly)

//@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-context.xml"})
public class MyTest {

This is using 0.11 of junit-interface library
libraryDependencies += "com.novocode" % "junit-interface" % "0.+" % "test"
...
Resolving com.novocode#junit-interface;0.11-RC1

Does not report failures in cucumber scenario outline results

Cucumber tests with Data Tables will pass with failing examples as long as the first example passes.

This happens because all the examples have the same fully qualified name that comes from the scenario outline description.

I have submitted a PR to fix this #83 .

Compatibility with Spring 4.3 and above

I have a project with a dependency on Spring Batch Test 4.1.0-RELEASE, which brings in Spring Test 5.1.2-RELEASE with it.

If I include junit-interface on the classpath, and plain dependencies (no exclusions) then ./sbt test gives:

[debug] Test run started
[debug] Test run finished: 0 failed, 0 ignored, 0 total, 0.001s

I have tried updated the dependencies to exclude JUnit 4.12, as follows:

libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
libraryDependencies += "org.springframework.batch" % "spring-batch-test" % "4.1.0.RELEASE" % "test" exclude("junit", "junit")

This gives the following from ./sbt test:

[debug] Running TaskDef(LoadInternalUsersTests, com.novocode.junit.RunWithFingerprint@310e1f40, false, [SuiteSelector])
...snip...
[error] Test LoadInternalUsersTests.initializationError failed: java.lang.ExceptionInInitializerError: null, took 0.004 sec
[error] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error] ...
[error] Caused by: java.lang.IllegalStateException: SpringJUnit4ClassRunner requires JUnit 4.12 or higher.
[error] at org.springframework.util.Assert.state(Assert.java:73)
[error] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.(SpringJUnit4ClassRunner.java:104)

In SpringJUnit4ClassRunner.java there is a note saying "As of Spring Framework 4.3, this class requires JUnit 4.12 or higher".

Is there a reason why junit-interface won't run the tests when JUnit 4.12 is on the classpath and 4.11 is evicted?

Impossible to tell what line caused test failure

The test failure messages are very frustrating because they don't include line numbers:

[error] Test com.benmccann.StringUtilTest.myTest failed: null
[info] com.benmccann.StringUtilTest
[info] x myTest

That makes it impossible to tell which line of this test failed:

@Test
public void myTest() throws Exception {
  Assert.assertTrue(MyClass.doSomething(1));
  Assert.assertTrue(MyClass.doSomething(2));
  Assert.assertTrue(MyClass.doSomething(3));
  Assert.assertTrue(MyClass.doSomething(4));
}

Exception type is swallowed

When a test fails due to an exception, junit-interface swallows the exception type, which makes debugging much more difficult.

Add another project maintainer

@szeiger i know you've been a bit busy and have had a hard time keeping up with some of the issues and pull requests. Perhaps you could add another maintainer to the project to help reduce the burden? There's a chance someone creates a fork of this project if that's the only way to get fixes into it and I think that forks aren't a great situation for anyone since they cause lots of confusion. Perhaps @backuitist or someone at Typesafe would be interested in helping out?

SBT 0.13.13 compatibility

Updating the build.properties to sbt.version=0.13.13 and running scripted shows that the categories suite fails. I ran into this because I was having a problem getting JUnit tests to run when using sbt on a java project - so far I've only seen it affect tests written in Java.

I'm planning to look into this and open a pull request (assuming I can fix the problem), but I was curious whether anyone here knows something that might have changed in 0.13.13 which would cause this breakage?

-a option should be the default

The error messages are quite unhelpful if -a is not set. This has caused me countless hours of frustration before I realized the option existed.

When you have output like the following, it's impossible to figure out what line the test is failing on when it's a large file with multiple assertions. All we get is "failed: null" and no line number or stacktrace, which was a recurring source of annoyance for the developers on our team.

$ ./activator test
[info] Loading project definition from /home/bmccann/src/play-java/project
[info] Set current project to play-java (in build file:/home/bmccann/src/play-java/)
[error] Test ApplicationTest.simpleCheck failed: null, took 0.02 sec
[error] Failed: Total 3, Failed 1, Errors 0, Passed 2
[error] Failed tests:
[error]     ApplicationTest
[error] (test:test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 5 s, completed Nov 20, 2014 10:16:48 PM

Release new version

There have been lots of fixes and changes recently. It would be great to test sbt & play with the latest code and release an RC

Doesn't run any junit tests when ignore-runners flag is used

Project that simulates the problem:

https://github.com/nraychaudhuri/junit_interface_ignore_runners_bug

Here is the summary:

I have one junit and one specs test with @RunWith annotation. If you run "sbt test" by commenting out the following line, it will run junit test and specs test twice

testOptions in Test += Tests.Argument("junitxml", "console", "--ignore-runners=org.specs2.runner.JUnitRunner")

Now add the line back to fix the @RunWith issue. But now junit tests will not run anymore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.