Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run tests in broken project using SBT

Tags:

scala

sbt

When doing a serious refactor in a Java Eclipse project I will often break the build, but focus on getting one test to pass at a time. When running the tests Eclipse warns that the project cannot be compiled, but it will still run the tests it can compile.

Now I'm using SBT and would like to achieve the same thing with 'test-only', but it tries to compile the whole project, fails, and doesn't run the tests. How can I tell it to just compile the bits it can and run the tests.

like image 791
Pengin Avatar asked Feb 24 '11 12:02

Pengin


1 Answers

You should add the following task to your project definition:

import sbt._

class Project(info: ProjectInfo) extends DefaultProject(info) {

  lazy val justTest = testTask(testFrameworks, testClasspath, testCompileConditional.analysis, testOptions)

}

This is the same as the ordinary test task, but has no dependencies attached at the end. If you'd like it to have dependencies, call dependsOn on the testTask(...) expression and provide the tasks you want it to depend on.

testTask(testFrameworks, testClasspath, testCompileConditional.analysis, testOptions).dependsOn(testCompile, copyResources, copyTestResources) 
like image 199
axel22 Avatar answered Oct 12 '22 23:10

axel22