darlik darlik - 1 year ago 137
Java Question

How to use assertTrue?

I have:

package com.darlik.test;

import org.junit.Assert;

public class Test {

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


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

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

Why? I use Eclipse.

Answer Source

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;

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

public class MyTest {

   public void testAssert() throws Exception {
        assertEquals(1, 2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download