java - junit 错误 - AssertionFailedError

标签 java junit

我是 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;

resultfalse,因此以下语句无法断言

 Assert.assertTrue(result);

关于java - junit 错误 - AssertionFailedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11073408/

相关文章:

java - 将异常转换为 JSON

java - ArrayStoreException : sun. reflect.annotation.TypeNotPresentExceptionProxy 安卓 PowerMock JUnit

java - Spring Boot Junit测试通过构造函数注入(inject)注入(inject)dao接口(interface)

java - RabbitMQ Java 客户端 - 如何明智地处理异常和关闭?

java - 限制 float 参数的允许值

java - 面向人类的 JAAS

spring-mvc - Mockito 与 Spring mvc

java - 如何在一个 JFrame 上显示两个对象同时保持其位置?

java - 使用 Mockito 对 SharedPreferences 包装器进行单元测试

eclipse - 通过 Eclipse 运行 JUnit 测试时的 Maven surefire 参数