Saturday, 9 November 2013

JUnit Hello World in its simplest form

Here is a very simple, very short example of running JUnit.


Assumptions: using Eclipse
Get: JUnit jar - this might actually be in Eclipse, I've never paid enough attention to this.
You might need to associate JUnit to the project's build path.
The reason for vagueness is I control+1 all of my errors to quick fix them, and minimize my own learning at the same time.

So, what to  do:

Write a test class
e.g.
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class HelloJUnit{
@Before
public void myBefore(){
System.out.println("This is the before bit");
}
@After
public void myAfter(){
System.out.println("This is my after");
}
@Test
public void makePie(){
System.out.println("Make me some pie");
}
@Test
public void moarPies(){
System.out.println("Make me even moar pies");
}
}
Then in eclipse you go Run > Run Configurations... and choose a new JUnit test. Get it to run all, or whatever, and click go/run. 

No comments:

Post a Comment

Robot Framework, Basic Setup

Plug: Robot Framework is quick to setup, easy to write tests for, and super fast to triage failures in. The last point really sets it apart...