使用 SBT 在损坏的项目中运行测试 [英] Run tests in broken project using SBT

查看:39
本文介绍了使用 SBT 在损坏的项目中运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java Eclipse 项目中进行认真的重构时,我经常会破坏构建,但专注于一次通过一个测试.运行测试时,Eclipse 警告无法编译该项目,但它仍会运行可以编译的测试.

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.

现在我正在使用 SBT 并希望使用仅测试"来实现相同的目标,但它尝试编译整个项目,失败,并且不运行测试.我怎么能告诉它只编译它可以编译的部分并运行测试.

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.

推荐答案

您应该将以下任务添加到您的项目定义中:

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)

}

这与普通的 test 任务相同,但最后没有附加依赖项.如果您希望它具有依赖项,请在 testTask(...) 表达式上调用 dependsOn 并提供您希望它依赖的任务.

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) 

这篇关于使用 SBT 在损坏的项目中运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆