I am writing a simple microbenchmarking tool in Scala. I want to be able to define tests and have them register themselves (or register them) on load of the test framework. AFAIK there are 2 ways of doing this
- Reflection - the test runner searches class path that match test.
- Statically - in java I could have a static init block that registers the test
I am having troubles do either of these in Scala. Here is the basic constructs of the program.
class TestRunner extends App {
val tests = Seq[BaseTest]
//... run the tests
}
abstract class BaseTest {
def run
}
Clients will extend BaseTest and when the App starts the Runner can run them.
Reflection I have not been able to find a working class-path searcher (note I am using Scala 2.12.5) to find sub classes of BaseTest. Is there a good way of writing this code using the Scala (or java) reflect libraries.
Static Block I have tried having a companion object the registers the test, however this object does not get instantiated until referenced (a way around this) and the code never executes.
Any thoughts on solving this issue is welcome.
Thanks
Aucun commentaire:
Enregistrer un commentaire