11

I have a new Scala/sbt project set up in IntelliJ IDEA with ScalaTest and jUnit interface successfully installed as dependencies. I have one test that passes when I hit run or debug.

My problem is that it doesn't rerun if I change something. I have to hit run or debug again and then it runs and gives the expected response.

How do I set up IntelliJ IDEA (with or without sbt) to run all tests every time the code changes? Is it possible to run the tests related to the files that were changed only?

Antony Stubbs
  • 13,161
  • 5
  • 35
  • 39
Mark
  • 3,137
  • 4
  • 39
  • 76
  • 8
    Open the `sbt console` and run `~test`. – Boris the Spider Jun 17 '14 at 21:22
  • ok thanks that works in the console but is there no way to get the feedback in the intellij testrunner? – Mark Jun 17 '14 at 21:24
  • 2
    For that you'll have to wait for one of the Intellij experts. Would be interested to know that too. – Boris the Spider Jun 17 '14 at 21:26
  • your solution certainly works in the mean time thanks. – Mark Jun 17 '14 at 21:27
  • 2
    There is a plug-in for IDEA that allows SBT to run in one of its tool windows. The added bonus is that compiler diagnostics become hyperlinked to the source code. – Randall Schulz Jun 17 '14 at 21:52
  • Actually if you use 'save on run' option you can still test with one key hit. – gwenzek Jun 18 '14 at 09:44
  • Or you can record a macro. E.g. I bound on Ctrl+s to save and then compile everything. You can probably create a similar shortcut to run all tests. But the best thing is to use sbt with testQuick, it executes failed and re-compiled tests. Exactly what you need. With the sbt-console plugin you also get highlighting in IntelliJ on failed tests, etc. – Elmar Weber Jul 22 '14 at 19:25

1 Answers1

2

As answered in comment by Boris the Spider you can run

> ~test

from sbt shell. Hopefully sbt and IntelliJ can integrate better via sbt server, but I don't think it's currently possible.

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319