0

I have multiple Scala classes in different packages and each has its own test. In case it matters, they all extend org.scalatest.flatspec.AnyFlatSpecLike class. One of these tests manipulates System.out (I know that in general that is not a good idea, but that is not the subject of this post). A few other tests check log messages.

Suppose these two kinds of tests are in classes A, B, and C, and many many other tests are in other classes/files. How can I make sure

  1. the execution of A, B, and C will be sequential. That is when tests in A are running, no other test (not just tests from B and C) is running.
  2. When none of these three suits are running, there is no restriction on the parallel execution of other tests?
Koosha
  • 1,492
  • 7
  • 19
  • 1
    Why you need to do that? Pretty often it's not a good practice: a test should be self consistent, if an external action can affect it, it means the test fails by design. Anyway what have you tried? just googling it there are many answers related to this. – il.bert Mar 21 '21 at 06:05
  • In some corner cases, which happens very rarely, I want to change `System.out`. I agree that *in general*, changing `System.out` is not a good approach. But imagine that that case happened. I think explaining what that case is, why do I need that, what are the alternatives, better solutions are out of the scope of this post. – Koosha Mar 21 '21 at 06:13
  • A more realistic example is `LogCapturing` feature provided by AKKA framework. When I test class `A` for its logs, no other test should use this class. Otherwise, logs will be messed up. Also, `getLogger` returns an object that is shared between threads. So any test that wants to test logs from class `A` must not be run concurrently with tests that use class `A`. – Koosha Mar 21 '21 at 06:16
  • What have you tried? Googling for it there are many proposals. An example https://stackoverflow.com/questions/11258428/how-make-tests-always-run-in-same-order-in-scalatest – il.bert Mar 21 '21 at 09:16

0 Answers0