Anybody have success running Specs tests via Run As...?

I've tried all kinds of permuations, and cannot get idea to recognize the test class. As per the Specs docs I did:

package foo
class ContractQuantityTests extends JUnit4(ContractQuantitySpec)
object ContractQuantitySpec extends Specification { .. }

The file ContractQuantityTests.class does exist in the output directory, but idea does not recognize the test class when creating a run config. And if I manually add the test class to the run config, I get an error when launched: "Class foo.ContractQuantityTests not found in module 'mymodule'".

Writing standard junit3/4 tests works just find. But has anybody gotten Specs or ScalaTests to run via the IDE?

0
7 comments

A bit of pilot error on my part. I had the wrong module specified in the config. Now idea will run the test, but it complains that it finds no tests. Here's my full example

class ContractQuantityTests extends JUnit4(ContractQuantitySpec)
object ContractQuantitySpec extends Specification {



  "number equality should" should {
    "return false when different" in {
      val ten = 10
      val eleven = 11
      ten != eleven
    }
    "return true when same" in {
      val ten = 10
      ten == ten
    }
  }
}


Is it that idea is deciding there are not test methods and not giving the Specs code a chance to build the suite?

0

I think I found the problem. First let me simplify my examples.

This test, when run in Idea will result in the message "junit.framework.AssertionFailedError: No tests found in com.tm.types.SpecsSpikeRunAsTests" with the top of the stack trace of "at com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:94)

class SpecsSpikeRunAsTests extends JUnit4(SpecsSpikeSpec)
object SpecsSpikeSpec extends Specification {


  "'hello world' has 11 characters" in {
     "hello world".size must beEqualTo(11)
  }
  "'hello world' matches 'h.* w.*'" in {
     "hello world" must beMatching("h.* w.*")
  }
}


If you look the definition fo JUnit4 you will see:

@RunWith(classOf[JUnitSuiteRunner])
class JUnit4(val specifications: Specification*) extends JUnit {
  val specs: Seq[Specification] = specifications
}


So I tried a few experiments, and ended up simply adding the annotation to my test, eg:

@RunWith(classOf[JUnitSuiteRunner])
class SpecsSpikeRunAsTests extends JUnit4(SpecsSpikeSpec)
object SpecsSpikeSpec extends Specification {



  "'hello world' has 11 characters" in {
      "hello world".size must beEqualTo(11)
   }
   "'hello world' matches 'h.* w.*'" in {
      "hello world" must beMatching("h.* w.*")
   }
}


Now both tests run in Idea's junit runner! You can even right click on the class to run the test. The output is a bit strange, as each test shows "0 test caes(s)" as the node name.

So the question is, do we have a compiler bug or an IDE or a ScalaPlugin bug? Or could be that Specs, when compiled, is missing a compiler switch that retains annotations?

0

ScalaPlugin doesn't support SpecTests yet (now you can run ScalaTest: http://www.artima.com/scalatest/). So If you can run something it's just JUnit. JUnit runner in IDEA works well (and it's not part of scala plugin), it's probably problems with Spec library.

Best regards,
Alexander Podkhalyuzin.

0

When I try to use the ScalaTest config I get class-not-found exceptions (I added a jira issue for this). But I have no problems running tests of the form:

class ContractQuantityTests extends JUnit3Suite with Checkers with ShouldMatchers {

  def testCheck1() {
    check((n: Int) => scala.Math.sqrt(n*n) == n)
  }

  ...
}

Idea sees the class as a junit test and runs the tests just fine.

I /can/ run the spec tests as I illustrated above. Any idea though about the need to explicity add the @RunWith annotation. At some point its getting lost via inheritance -- either from the scala compiler, idea -- I'm guessing it has nothing to do with the scala plugin.

Overall I must the say the scala-plugin is comming along very very nicely. I jump back and forth between idea, eclipse and netbeans and always come back [immediatly] to idea.

0

Hi,

I've looked at the specs integration with Intellij, w.r.t. JUnit.

There seems to be 2 issues:

1. the RunWith annotation

I don't know why the annotation is not found on the specification class. In the latest version of specs you can write:

class mySpec extends Specification with JUnit { ... }

where the Specification class holds the RunWith annotation. This annotation being "Inherited" by definition, I don't see why Intellij doesn't recognize mySpec as having it (any idea?).
On the other hand, the annotation is recognized in both Eclipse and Maven.

2. the suites and tests descriptions

The idea test runner makes some assumptions about the way suites and tests are structured.

When the RunNotifier is passed a "Description" object saying which test started, it uses an internal TestResult object notified with a "Test" instance.

But this Test instance is not the original test object created by specs with the passed "Description". It is a JUnitMethodAdapter object built by extracting from the "Description":

- a class name
- a method name

assuming that the description is "method name(class name)". But this assumption doesn't hold for specs Specifications as there aren't classes holding individual tests.

As a temporary workaround, I have slightly changed the description creation in specs so that the ExampleTestCase class name is showing up. With this, the examples descriptions are at least visible in the GUI (but not the system names). This new version is available here.

I would like to make things better, but I don't think that's possible without writing a specific specs plugin (which I don't have time to build for now but I'd be happy to collaborate with anyone starting it).

Cheers,

Eric.

0

As I see, last spec release (from 12 februrary) don't have RunWith annotation with Specification. So I don't see this issue for now.

About spec tests in scala plugin.
If specs have ability to report next things:


runStarting with test count number
testStarting with test name
testSucceeded with test name
testFailed with stacktrace and test name
testIgnored with test name
suiteStarting with suite name
suiteCompleted with suite name



 


For example how it provided in ScalaTest. They give Reporter trait with (more then I said) methods. I use this reporter, and in this methods print stdout in such way as I need.
If this exist in specs, please give me hint for it. If not, I hope it can be simply added. After this, I can add ScalaSpecs runner in IDEA quickly.

Best regards,
Alexander Podkhalyuzin.

0

I just finished implementing a very straightforward RunNotifier (available here ):

      // declare a notifier

      notifier = new Notifier {
         // implement the methods

        def runStarting(examplesCount: Int) = ...
        def exampleStarting(exampleName: String) = ...
        def exampleSucceeded(testName: String) = ...
        def exampleFailed(testName: String, e: Throwable) = ...
        def exampleError(testName: String, e: Throwable) = ...
        def exampleSkipped(testName: String) = ...
        def systemStarting(systemName: String) = ...
        def systemCompleted(systemName: String) = ...

      }


 

      // use the notifier
      new NotifierRunner(s, notifier).reportSpecs

I just changed the naming so that it is more aligned on the BDD syntax.

On the other hand I realized that any Specification can be run as a ScalaTest suite:

import org.specs.runner.ScalaTestSuite
val suite = new ScalaTestSuite(spec)

So this may be the easiest way to run seamlessly specs Specifications in IntelliJ.

Eric.



0

Please sign in to leave a comment.