编写 junit 测试时:
internal class MyTest {
@org.junit.jupiter.api.Nested
class MyInnerClass {
}
}
我的代码编辑器 (IntelliJ) 显示警告
Only non-static nested classes can serve as @Nested test classes.
如何在 kotlin 的 junit 测试中编写嵌套类?
最佳答案
在 kotlin 中使用 @Nested 类时,它们需要前缀 inner,因为只有内部类才能用作嵌套类。
Only non-static nested classes (i.e. inner classes) can serve as @Nested test classes.
您的代码应该看起来像这样:
internal class MyTest {
@Nested
inner class MyInnerClass {
@Test
fun customTest() {
//TODO: do something
}
}
}
关于kotlin - 如何在 kotlin 中编写@Nested 测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66135286/