我正在尝试模拟学生班的最后一个领域
data class Student(
val id: Int,
val name: String,
val marks: Marks
)
data class Marks(
val subject1: String
)
这是我的测试课
class StudentTest {
@Test
fun testStudentMarks() {
val student = mock(Student::class.java)
assertNotNull(student.id)
assertNotNull(student.marks)
}
}
在运行测试时,它通过了 student.id,但在 student.marks 上失败,并出现以下错误
junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:55)
at junit.framework.Assert.assertTrue(Assert.java:22)
at junit.framework.Assert.assertNotNull(Assert.java:256)
at junit.framework.Assert.assertNotNull(Assert.java:248)
at com.example.mockitotest.StudentTest.testStudentMarks(StudentTest.kt:16)
我如何模拟标记字段