Java – 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);
    }

}

Include org JUnit's package has been set up and works normally, but it is consistent with asserttrue. I have an error:

Why? I use eclipse

Solution

Asserttrue is based on a single Boolean condition for example

assertTrue(1 == 2);

You need static import statements to use

import static org.junit.Assert.assertTrue;

Generally, assertequals is used when comparing two parameters, for example,

public class MyTest {

   @Test
   public void testAssert() throws Exception {
        assertEquals(1,2);
   }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>