1

My team is using Scala, IntelliJ, and Maven.

In the some of the tests I need for the current module I am working on the internal test order of execution is important.

For some reason running the same test using JUnit or ScalaTest in IntelliJ effects the order of execution.

For example, the following test:

package com.liveperson.lpbt.hadoop.monitoring.temp

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, BeforeAndAfterAll}


@RunWith(classOf[JUnitRunner])
class TempTest extends FunSuite with BeforeAndAfterAll{

  println("start TempTest")

  override def beforeAll(){
    println("beforeAll")
  }

  override def afterAll(){
    println("afterAll")
  }

  test("test code"){
    println("in test code")
  }

  println("end TempTest")
}

When running with JUnit the above code prints outs:

start TempTest
end TempTest
in test code
beforeAll
afterAll

When running with ScalaTest the above code prints outs:

start TempTest
end TempTest
beforeAll
in test code
afterAll

Does somebody knows how to write such test ensuring the order of execution in both ScalaTests and JUint? Also, how do you switch between them in IntelliJ?

1 Answers1

0

Can you elaborate on exactly how you got the JUnit output? I just tried doing your class from the command line and got the expected output (different from yours):

Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/ org.scalatest.run TempTest
start TempTest
end TempTest
Discovery starting.
Discovery completed in 19 milliseconds.
Run starting. Expected test count is: 1
beforeAll
TempTest:
in test code
- test code
afterAll
Run completed in 140 milliseconds.
Total number of tests run: 1
Suites: completed 1, aborted 0
Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
All tests passed.

Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/ org.junit.runner.JUnitCore TempTest
JUnit version 4.8.1
Could not find class: TempTest

Time: 0.001

OK (0 tests)

Mi-Novia:roofSoccer bv$ scala -cp ~/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar:target/jar_contents/:. org.junit.runner.JUnitCore TempTest
JUnit version 4.8.1
start TempTest
end TempTest
beforeAll
.in test code
afterAll

Time: 0.078

OK (1 test)
Bill Venners
  • 3,549
  • 20
  • 15
  • Hi Your output is similar to the second output in my earlier post. As I mentioned before I am running using IntelliJ and two possible different ways to run test in it. I also tried to run in the command line using Maven. – Mishael Rosenthal Aug 14 '13 at 21:01
  • The commands I used to run directly on the command line are shown in my response above. I'm just boarding a flight now but will try this in IntelliJ later to see if I can reproduce your issue. – Bill Venners Aug 15 '13 at 20:07