How do I start the server as part of a test?

I am writing a simple REST API using spray , and as part of that, I would like to be able to install using a database with mock data, then deploy a REST server using that test database.

The problem is, I really don't know how I need to start a test instance to run and run to run tests. Please guide.

+3


source to share


2 answers


The difference between tests and production code in terms of sbt is mostly the location of the code. It is controlled by the config scope parameter in sbt :

The config defines the flavor of the assembly, potentially with its own classpath, sources, generated packages, etc. The configuration concept comes from Ivy, which sbt uses for dependency library dependencies, and from MavenScopes.



What you can do in an area Compile

should be easily applicable to Test

and vice versa. It may or may not be as easy as it sounds, but there shouldn't be many hoops along the way.

As I pointed out in the comment , when you do sbt run

as if you did sbt compile:run

... well, almost, but you can assume it does. Set up a test instance of your database and server and run them all with, sbt test:run

or even better - write a test, perhaps an integration test, that does whatever it needs to do as part of running it and give it a run with sbt it:test

- see Integration Tests .

+2


source


You can add an object to / src / test. This object will load your server just like it normally would, except that you are using a mock database.

If you don't identify this object as a test class, it won't interfere with your test suite. It depends on the test system used.



For example, in Spec2, it automatically runs any test class that extends the specification. If you don't extend this class, it won't run.

Additional segregation at the packet level might make sense.

+1


source







All Articles