Java 向时间戳添加5秒的JUnit测试:没有为参数[object]注册ParameterResolver

Java 向时间戳添加5秒的JUnit测试:没有为参数[object]注册ParameterResolver,java,testing,junit,Java,Testing,Junit,我编写了一个更新对象时间戳的方法。它工作正常,值按预期方式更新。但是,我无法让单元测试工作 Cake有一个值inspectiondate,该值用首次创建对象的时间戳初始化 这是我的方法: public static void updateInspectionDate(Cake cakeToBeUpdated){ cakeToBeUpdated.setInspectDate(new Date(System.currentTimeMillis())); } 这是我的测试

我编写了一个更新对象时间戳的方法。它工作正常,值按预期方式更新。但是,我无法让单元测试工作

Cake有一个值inspectiondate,该值用首次创建对象的时间戳初始化

这是我的方法:

public static void updateInspectionDate(Cake cakeToBeUpdated){ 
        cakeToBeUpdated.setInspectDate(new Date(System.currentTimeMillis()));
    } 
这是我的测试(尝试了几种测试方法,这是我的当前版本),obejct已经在测试类中创建:

@Test 
    void updateInspectionDateTest(Cake apple) throws InterruptedException {
        Calendar newInspectionDate = Calendar.getInstance(); //create new date that`s current inspection date + 5 seconds
        newInspectionDate.setTime(apple.getInspectiondate());
        newInspectionDate.add(Calendar.SECOND, 5);

        TimeUnit.SECONDS.sleep(5); //wait 5 seconds
        updateInspectionDate(apple); //inspection date of apple will be updated to 5 seconds after it was inserted

        assertEquals( newInspectionDate.getTime(), apple.getInspectiondate());
    } 
这就是我得到的错误:

org.junit.jupiter.api.extension.ParameterResolutionException:没有为方法[void CakeTest.updateInspectionDate(Cake)抛出java.lang.InterruptedException]中的参数[Cake arg0]注册ParameterResolver]


那么到底出了什么问题以及如何解决这个问题呢?

您已经创建了一个带有参数的测试方法。通常,测试没有参数。仅当它们由参数化运行执行时(对多个值运行相同的方法)


您的测试方法应该类似于
void updateInspectionDateTest()
。但请考虑一个更有意义的名称,而不仅仅是它应该测试的名称。

谢谢,这就解决了问题!