I am attempting to run a test for a Scalatra route using ScalatraSuite (FunSuiteLike). I receive an IllegalArgumentException with the following error when running the test:
The detected local port is < 1, that's not allowed
I also tried running Jetty separately and then running "sbt test", but the same error comes up. Can anyone please help to resolve this issue?
I had this same error and was able to figure out what the cause was.
In my case, I had mixed in a trait that had overridden the beforeAll and afterAll methods. This meant that the beforeAll and afterAll defined in ScalatraSuite were not being run. Here's the quote from Scalatra's documentation for ScalatraSuite that helped me to figure out what the problem was:
Notice that all the above traits are based on
ScalatraSuitewhich mixes inBeforeAndAfterAll. It overrides bothbeforeAll()andafterAll()so it can start/stop the embedded HTTP server. Because of that, if your test classes also need to overridebeforeAlland/orafterAlljust remember to callsuper.beforeAll()and/orsuper.afterAll().
Since my custom beforeAll hook was not invoking super.beforeAll(), Scalatra's mechanism to launch the HTTP server was not invoked, and thus no test-server was running. Adding the super.beforeAll() to my custom beforeAll method fixed the problem.
In my case, I had to redesign the beforeAll steps in my project, so that a number of different dependencies could be set up... but I was able to ensure that beforeAll() in ScalatraSuite was called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With