Search code examples
scalasbtspecs2

Running only a specific Spec from SBT that has constructor parameters


I have a Specification to test database related things against multiple databases. Therefore it gets the database configuration to test against via its constructor parameters. It is instantiated and used from a bigger spec which tests against all the databases.

Now I only want to test against lets say MSSQL in sbt but if I use test-only f.q.d.n.MySpec(DatabaseConfig.MSSQL) no tests are run because it does not match any tests. If I leave the parameter off it tries to instantiate the class and rightfully fails because it cant instantiate it without parameters.

Is there a way to only run a specific specification with a specific set of constructor parameters from sbt without changing the bigger spec that calls it?


Solution

  • When you use test:only you need to pass an expression matching the class name (using * if needed). Then specs2 will try to instantiate your constructor parameters if they have a constructor with 0 arguments. This is not the case if you pass an object. Can you try to a have class with a 0 argument constructor instead?