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.
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.
You have to specify the class that defines that method:
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:
which will allow you to call it as
assertTrue(condition);
instead.assertTrue
is based on a single boolean condition. For exampleYou need to import the statement statically to use
Typically, however
assertEquals
is used when comparing 2 parameters, e.g.Better try assertThat with matchers. Check this blog about it https://objectpartners.com/2013/09/18/the-benefits-of-using-assertthat-over-other-assert-methods-in-unit-tests/