How do I define the main method of Scala objects in a common place?
In several Scala objects, I have defined a main method that calls runTests, which is an abstract method in Test. Is there a way that the main method can be split into a common location (Trait or some other solution) so that I can execute the test in Eclipse by pressing ctrl- F11?
This is what I currently have,
https://github.com/janekdb/stair-chess/blob/master/src/chess/model/BoardModelTest.scala
object BoardModelTest extends Test with TestUtils {
def main(args: Array[String]) {
runTests
}
def runTests {
...
https://github.com/janekdb/stair-chess/blob/master/src/test/Test.scala
trait Test {
def runTests: Unit
...
+3
source to share
1 answer
I don't have Eclipse on this computer, so I can't check if it works with Ctrl + F11, but I think you want to have the type:
trait Main {
self: Test =>
def main(args: Array[String]) {
runTests
}
}
Then you just paste it after your dash Test
:
object BoardModelTest extends Test with TestUtils with Main {
def runTests {}
}
+8
source to share