如何在测试文件夹中运行主类?

Joh*_*n S 15 scala sbt

如果我maintest项目文件夹中有一个带方法的简单对象,我该如何用sbt运行它?

Ken*_*ida 37

sbt "test:runMain path.to.MainObjectInTest"
Run Code Online (Sandbox Code Playgroud)


use*_*663 5

...如果你的 sbt 文件中有多个项目,那么:

sbt "projectName/test:runMain path.to.MainObjectInTest"
Run Code Online (Sandbox Code Playgroud)

或者只是使用:

sbt "projectName/test:run"
Run Code Online (Sandbox Code Playgroud)

如果您只有一个带有 main 的对象,这将运行它。如果您有多个带有 main 的对象,它会要求您选择要运行的对象。