我正在从Coursera学习反应式编程原理课程。 在其中一个作业中,我需要使用scalacheck类。 我在Intellij中打开了以下测试类:
package quickcheck
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop
import org.scalacheck.Prop._
import org.scalatest.exceptions.TestFailedException
object QuickCheckBinomialHeap extends QuickCheckHeap with BinomialHeap
@RunWith(classOf[JUnitRunner])
class QuickCheckSuite extends FunSuite with Checkers {
def checkBogus(p: Prop) {
var ok = false
try {
check(p)
} catch {
case e: TestFailedException =>
ok = true
}
assert(ok, "A bogus heap should NOT satisfy all properties. Try to find the bug!")
}
test("Binomial heap satisfies properties.") {
check(new QuickCheckHeap with BinomialHeap)
}
test("Bogus (1) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus1BinomialHeap)
}
test("Bogus (2) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus2BinomialHeap)
}
test("Bogus (3) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus3BinomialHeap)
}
test("Bogus (4) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus4BinomialHeap)
}
test("Bogus (5) binomial heap does not satisfy properties.") {
checkBogus(new QuickCheckHeap with Bogus5BinomialHeap)
}
}
当我尝试运行它时,我得到了这个输出:
+ Heap.min1: OK, passed 100 tests.
+ Heap.minOfTwo: OK, passed 100 tests.
+ Heap.insertAndDelete: OK, passed 100 tests.
Heap.min1
,Heap.minOfTwo
,Heap.insertAndDelete
是我想要检查的方法,这样做很好。但是,它们通过的测试与我尝试运行的测试文件没有任何关联。
如何从Intellij正确运行此测试文件?我可以从其他地方(例如sbt
控制台)运行它吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
在IntelliJ中,在编辑器中打开该文件并不能确保它是执行测试时将运行的测试类。您的项目可以包含多个运行/调试配置,您可以使用protected void DoPostBack(object sender, EventArgs e)
{
OpenSerialPort();
binStatus = _sensorPort.ReadLine();
CloseSerialPort();
}
进行编辑。要仅执行Run > Edit Configurations
中定义的测试,您需要将quickcheck.QuickCheckSuite
设置为Test Class:
的ScalaTest配置。然后,您可以使用quickcheck.QuickCheckSuite
执行它。
或者,从sbt开始,你可以运行
Run > Run…