Question

I have a ScalaTest which extends the FlatSpec. I have many tests inside the test and I now want to have the possibility to run one test at a time. No matter what I do, I can't get IntelliJ to do it. In the Edit Configurations of the test, I can specify that it should run one test at a time by giving the name of the test. For example:

it should "test the sample multiple times" in new MyDataHelper {
  ...
}

where I gave the name as "test the sample multiple times", but it does not seem to take that and all I get to see is that it just prints Empty Test Suite. Any ideas how can this be done?

Was it helpful?

Solution 2

An approach that works for me is to right-click (on Windows) within the definition of the test, and choose "Run MyTestClass..." -- or, equivalently, Ctrl-Shift-F10 with the cursor already inside the test. But it's a little delicate and your specific example may be causing your problem. Consider:

class MyTestClass extends FlatSpec with Matchers {

  "bob" should "do something" in  {
    // ...
  }

  it should "do something else" in  {
    // ...
  }

  "fred" should "do something" in  {
    // ...
  }

  it should "do something else" in  {
    // ...
  }
}

I can use the above approach to run any of the four tests individually. Your approach based on editing configurations works too. But if I delete the first test I can't run the second one individually -- the others are still fine. That's because a test that starts with it is intended to follow one that doesn't -- then the it is replaced with the appropriate string in the name of the test.

If you want to run the tests by setting up configurations, then the names of these four tests are:

  • bob should do something
  • bob should do something else
  • fred should do something
  • fred should do something else

Again, note the substitution for it -- there's no way to figure out the name of a test starting with it if it doesn't follow another test.

I'm using IntelliJ Idea 13.1.4 on Windows with Scala 2.10.4, Scala plugin 0.41.1, and ScalaTest 2.1.0. I wouldn't be surprised if this worked less well in earlier versions of Idea or the plugin.

OTHER TIPS

If using Gradle, go to Preferences > Build, Execution, Deployment > Build Tools > Gradle and in the Build and run > Run tests using: section, select IntelliJ IDEA if you haven't already.

I just realized that I'm able to run individual tests with IntelliJ 13.1.3 Community Edition. With the one that I had earlier 13.0.x, it was unfortunately not possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top