如何使用assertTrue? [英] How to use assertTrue?

查看:1424
本文介绍了如何使用assertTrue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

package com.darlik.test;

import org.junit.Assert;

public class Test {

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

}

使用org.junit软件包并正常工作,但符合assertTrue,但我有错误:

package with org.junit is set and working but in line with assertTrue i have error:


对于类型Test类型,未定义方法assertTrue(int,int)

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

为什么?我使用Eclipse。

Why? I use Eclipse.

推荐答案

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

assertTrue is based on a single boolean condition. For example

assertTrue(1 == 2);

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

You need to import the statement statically to use

import static org.junit.Assert.assertTrue;

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

Typically, however assertEquals is used when comparing 2 parameters, e.g.

public class MyTest {

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

这篇关于如何使用assertTrue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆