How to set up Junit environment in Window OS?

1. Install Java environment

See this post

2. Download Junit archive and put the jar file into a folder (C:\JUNIT for example)

3. Set Junit environment

Set the environment variable JUNIT_HOME to C:\JUNIT

Set the environment variable CLASSPATH to %CLASSPATH%;%JUNIT_HOME%\junit-4.10.jar;.;

EnvirVar4. Example to using Junit: 

4.1 Create a file “” with following content:

import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJunit {
   public void testAdd() {
      String str= "Junit is working fine";
      assertEquals("Junit is working fine",str);

4.2 Create a file “” with following content:

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class TestRunner {
   public static void main(String[] args) {
      Result result = JUnitCore.runClasses(TestJunit.class);
      for (Failure failure : result.getFailures()) {

4.3 Put 2 both .java files into folder (C:\test for example). Run like the following: 


For more info please see:

Happy Juniting 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s