Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scalatra test failing using ScalatraSuite (FunSuiteLike) for standlone sbt project

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?

like image 760
rg41 Avatar asked Mar 14 '23 00:03

rg41


1 Answers

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 ScalatraSuite which mixes in BeforeAndAfterAll. It overrides both beforeAll() and afterAll() so it can start/stop the embedded HTTP server. Because of that, if your test classes also need to override beforeAll and/or afterAll just remember to call super.beforeAll() and/or super.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.

like image 168
sean_robbins Avatar answered Mar 17 '23 03:03

sean_robbins