1
votes

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

1 Answers

0
votes

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)