【发布时间】:2019-09-04 10:07:23
【问题描述】:
我正在使用 scalatest 的 FunSuite 运行我的测试。我想定义 2 个单独的测试类,它们有一些共同的测试,所以我创建了一个 BaseTest 类,我在 MainTest1 和 MainTest2 中扩展了它,在其中我定义了额外的特定测试(参见下面的代码 sn-ps )。我希望MainTest1 和MainTest2 中的测试以特定顺序执行,例如测试 4、2、1 和 3。我该如何实现?
class BaseTest extends FunSuite with BeforeAndAfter{
test("Check Content of file){
//code to check content of a file
}
test("File is not empty"){
//code to check file is not empty
}
test("Check a particular word in file"){
//code to check particular word in file
}
}
class MainTest1 extends BaseTest{
test("Check create file"){
//code to check file creation
}
}
class MainTest2 extends BaseTest{
test("Check download file"){
//code to check file downloaded properly
}
}
【问题讨论】:
-
写一个测试方法,把
test4, test2, test1, test3放在里面。 -
那么如果test4失败,test2,test3..不会执行
-
为什么需要以特定顺序执行测试?这似乎是一种反模式。另外,请提供一个最小的代码示例,以确保我们理解您的问题。
-
我已经添加了代码sn-p,请检查
-
您可以在
BaseTest中定义test1()、test2()etc 方法,以test("blah") { ... }作为它们的主体。然后,您可以从MainTest1和MainTest2依次调用这些方法。一旦问题不再暂停,我将提供完整的代码示例。