加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何使用assertTrue?

发布时间:2020-12-15 02:02:23 所属栏目:Java 来源:网络整理
导读:我有: package com.darlik.test;import org.junit.Assert;public class Test { public static void main(String[] args) { assertTrue(1,2); }} 包含org.junit的包已设置并正常工作但与assertTrue一致我有错误: The method assertTrue(int,int) is undefin
我有:

package com.darlik.test;

import org.junit.Assert;

public class Test {

    public static void main(String[] args) {
        assertTrue(1,2);
    }

}

包含org.junit的包已设置并正常工作但与assertTrue一致我有错误:

The method assertTrue(int,int) is undefined for the type Test

为什么?我用Eclipse.

解决方法

assertTrue基于单个布尔条件.例如

assertTrue(1 == 2);

您需要静态导入语句才能使用

import static org.junit.Assert.assertTrue;

通常,在比较2个参数时使用assertEquals,例如,

public class MyTest {

   @Test
   public void testAssert() throws Exception {
        assertEquals(1,2);
   }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读