4

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?

Chris W.
  • 1,680
  • 16
  • 35
rg41
  • 131
  • 2
  • 6

2 Answers2

7

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.

Chris W.
  • 1,680
  • 16
  • 35
sean_robbins
  • 684
  • 6
  • 17
0

Not a direct answer, but I ran into this same error and found that it was specific tests that would throw this error, not all. My issue ended up being a code formatting problem where a misplaced { made a single test encompass other tests.

So ultimately, if tests have been running and then stop with this error, its very likely a code related issue. I found this in scalatra.specs2, but the same could happen in ScalatraSuite.

Hope you worked out your issue.

vard
  • 4,057
  • 2
  • 26
  • 46
ekydfejj
  • 339
  • 2
  • 14