This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
第一次使用JUnit,到目前为止,它还不错。在测试中,我期望数字为128。我在代码中将其指定为:

assertEquals(myclass.myVar(), 228);


但是我从JUnit收到这样一个奇怪的错误:

expected:<418> but was:<228>
junit.framework.AssertionFailedError: expected:<418> but was:<228>


所以程序给了我正确的输出。我已经检查了没有JUnit只是为了确保。但是测试失败了。谁能阐明418号码是从哪里获得的?我没有在Junit测试文件中的任何地方指定它。

TIA

最佳答案

你的观点是错误的。它应该是:

assertEquals(expectedValue, actualValue);


因此,您的测试应为:

assertEquals(228, myclass.myVar());


到那时,您将收到一条更合理的消息-然后您需要弄清楚myVar()实际上返回418的原因:)

09-25 16:47
查看更多