你好我有一个Person类和一个PersonTest.java来验证我的方法是否正常工作,我的一个方法确定并验证了人的年龄,但是我的测试类中出现了一个错误,即类中的方法getAge不能适用于给定类型; 必需:LocalDate 发现:没有参数
非常感谢任何帮助。下面是我的方法和测试方法。提前谢谢
public int getAge(LocalDate dob)
{
LocalDate today = LocalDate.now();
int age = Period.between(birthdate, today).getYears();
if (age >= 14 && age <= 115) // valid employee dob
this.birthdate = dob;
else
throw new IllegalArgumentException("the Person must be between 14- 115");
return age;
}
-------------------------这是我的测试方法------------------ ----
public void testGetAge(int age, LocalDate dob) {
System.out.println("getAge");
int expResult = 16;
int result = validPerson.getAge(); // heres the error
assertEquals(expResult, result);``
}
答案 0 :(得分:2)
正如我所见,getAge方法获取LocalDate
输入参数,但在测试类中,您调用它时没有任何参数。这就是你得到错误的原因:
required: LocalDate found: no arguments
只需将参数传递给它,或使其使用Person
年龄。