How to use assertTrue?
You have to specify the class that defines that method:
Assert.assertTrue(condition);
Furthermore you're calling the method with 2 parameters which makes no sense. assertTrue
expects a single boolean expression.
Although you can also do this by using a static import:
import static org.junit.Assert.*;
which will allow you to call it as assertTrue(condition);
instead.
From the doc : assertTrue(boolean) or assertTrue(String, boolean) if you want to add a message.
AssertTrue assert that a condition is true, you still have to code such condition for it to be evaluated at runtime.
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 {
@Test
public void testAssert() throws Exception {
assertEquals(1, 2);
}
}