0

So Im currently in a project where we are using Java playframework 2.3.7 with activator. One of the things I liked about playframework is the hot-reloading feature. I can modify java files save and the changes are compiled and refreshed on runtime.

How do I get that functionality but for testing? I want to be able to run a single test with this hot reloading feature, so that when I save. Tests for the given file (specified by test-only) is re-runned automatically.

jstuartmilne
  • 4,398
  • 1
  • 20
  • 30

2 Answers2

1

There is not such a solution, however you have two choices:

  1. Use IntellJ: To re-run the previous test(s) in IntellJ, you press shift + F10.

  2. Write a watcher: Write a file/directory watcher such as this question/answer here, and then as soon as there are changes, the program, re-runs the test command, such as sbt clean compile test or activator compile test.

Little advice auto running tests: I don't know how complicated your application is, but as soon as you have couple of injections here and there and with additional concurrency; you do not want to run the tests as soon as you put a char in.

Little advice on Test Driven Development: Your approach should be the other way around! You write a test, which fails because there is no implementation; then you leave it alone. You go and write the implementation, then rerun the test to pass it or to get a feedback. Again, you need your cpu/memory power to focus on one thing, you don't want to brute force your implementation. Hope this makes sense!.

Little advice on your Play version: The Play 2.6 is way much better than Play 2.3; you should slowly but surely update your application; at least for the sake of security.

o-0
  • 1,713
  • 14
  • 29
  • "Little advice on Test Driven Development" its kind of the reason i want to do this. Im running the tests through the console. I just don't want to go to the console and "type" the re-run, I want the same thing i do in React with Jest. "Little advice on your Play version:" I can't not my call :( Will try your watch idea. Thank u – jstuartmilne Aug 03 '18 at 13:23
0

Ok so I found what I was looking for. For anybody in need of this particular feature in that particular version of play (I'm not sure about other versions) what you need to do is really simple. run activator and put the ~ prefix before test. for example

#activator
[my-cool-project]~test

That will reload your tests when you make a change. if you want to do this for a particular test then you have to do the same but with test-only

#activator
[my-cool-project]~test-only MyCoolTest

hope it helps anyone looking for the same thing

jstuartmilne
  • 4,398
  • 1
  • 20
  • 30