我是 junit 测试的新手,我有以下测试 -
public class ItemsTest extends TestCase {
private Items itemsd;
protected void setUp() throws Exception {
super.setUp();
itemsd = new Items();
}
@Test
public void testGetCategory() {
boolean result = itemsd.getCategory() != null;
Assert.assertTrue(result);
}
}
它测试了这个非常非常简单的代码 -
/**
* @return Returns the category.
*/
public String getCategory() {
return category;
}
显然我在这里缺少一些简单的东西?
最佳答案
似乎您的 itemsd.getCategory()
返回 null
等等
boolean result = itemsd.getCategory() != null;
result
为 false
,因此以下语句无法断言
Assert.assertTrue(result);
关于java - junit 错误 - AssertionFailedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11073408/