Home » Core Java » junit » Page 7


JUnit Getting Started Example

In this example we are going to introduce some basic annotations and asserts of JUnit4. JUnit4 is a test framework which is used by developers so that they can be ensured that their code works as expected. 1. Create Junit Test Open Eclipse IDE and create a new Java project called JunitFirstTest. It would be better to create a new ...

Read More »

JUnit Rules Example

The implementation of a Rule might look like this: import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; public class LoggingRule implements TestRule { public class LoggingStatement extends Statement { private final Statement statement; public LoggingStatement(Statement aStatement, String aName) { statement = aStatement; } @Override public void evaluate() throws Throwable { System.out.println("before: " + name); statement.evaluate(); System.out.println("after: " + name); } } private ...

Read More »