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)

http://www.junit.org

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 “TestJunit.java” with following content:

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

4.2 Create a file “TestRunner.java” 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()) {
         System.out.println(failure.toString());
      }
      System.out.println(result.wasSuccessful());
   }
}

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

JunitTest

For more info please see:

http://www.tutorialspoint.com/junit/junit_environment_setup.htm

Happy Juniting 🙂

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s