gpt4 book ai didi

java - 如何使用assertTrue?

转载 作者:行者123 更新时间:2023-12-02 01:25:12 26 4
gpt4 key购买 nike

我有:

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基于单个 boolean 条件。例如

assertTrue(1 == 2);

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

import static org.junit.Assert.assertTrue;

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

public class MyTest {

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

关于java - 如何使用assertTrue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25352329/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com