Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JUnit - Environment settings


May 15, 2021 jUnit


Table of contents


Junit - Environment settings

Local environment settings

JUnit is a framework for Java, so the most fundamental need is to have JDK installed in your machine.

System requirements

Jdk 1.5 or more
Memory There are no minimum requirements
Disk space There are no minimum requirements
Operating system There are no minimum requirements

Step 1: Verify the Java appliance in your machine

Now open the console and perform the following java requirements.

Operating system Task Command
Windows Open the command operator's station c:>java -version
Linux Open the command terminal $ java -version
Mac Open the terminal machine:~ joseph$ java -version

Let's verify the output of all operating systems:

Operating system Output
Windows java version "1.6.0-21"
Java (TM) SE Operating Environment (build 1.6.0-21-b07)

Java Hotspot (TM) Client Virtual Machine (build 17.0-b17, hybrid mode, shared)
Linux java version "1.6.0-21"
Java (TM) SE Operating Environment (build 1.6.0-21-b07)

Java Hotspot (TM) Client Virtual Machine (build 17.0-b17, hybrid mode, shared)
Mac java version "1.6.0-21"
Java (TM) SE Operating Environment (build 1.6.0-21-b07)

Java Hotspot (TM) 64-Byte Server Virtual Machine (build 17.0-b17, hybrid mode, shared)

If you haven't installed Java yet, install the Java SDK http://www.oracle.com/technetwork/java/javase/downloads/index.html at the following URL. We use Java 1.6.0-21 as the installed version of this tutorial.

Step 2: Set up the JAVA environment

Set JAVA_HOME environment variable to point to the base directory location, where Java is installed on your machine.

OS Output
Windows Set the environment variable JAVA_HOME to C:\Program
Files\Java\jdk1.6.0_21
Linux Output JAVA_HOME //usr/local/java-current
Mac Output JAVA_HOME s/Library/Java/Home

The system path adds the Java compiler location.

OS Output
Windows Add a string at the end of the system variable path
; C:\Program Files\Java\jdk1.6.0_21\bin
Linux Output PATH- $PATH: $JAVA/bin/
Mac No, you don't need to

Use the Java-version command explained above to verify the Java installation.

Step 3: Download the Junit archive

Download the http://www.junit.org version of JUnit's compressed file from the computer. While writing this tutorial, I've downloaded Junit-4.10 .jar and copied it to the C:;JUnit folder.

OS The name of the file
Windows junit4.10.jar
Linux junit4.10.jar
Mac junit4.10.jar

Step 4: Set up the JUnit environment

Set JAVA_HOME environment variable to point to the base directory location, where junIT compressed files are installed on your machine. Suppose we have stored junit4.10 files in the JUNIT folders of the following .jar.

OS Output
Windows Set the environment variable JUNIT_HOME to C: .JUNIT
Linux Output JUNIT_HOME //usr/local/JUNIT
Mac Output JUNIT_HOME s/Library/JUNIT

Step 5: Set the CLASSPATH variable

Set the CLASSPATH environment variable to point to the JUNIT compressed file location. Suppose we have stored junit4.10 in the JUNIT folders of the following .jar.

OS Output
Windows Set the environment variable CLASSPATH to %CLASSPATH; %JUNIT_HOME%\junit4.10.jar;.;
Linux Output CLASSPATH: $CLASSPATH: $JUNIT.HOME/junit4.10.jar:.
Mac Output CLASSPATH: $CLASSPATH: $JUNIT.HOME/junit4.10.jar:.

Step 6: Test JUnit build

In C: Create a JUNIT_WORKSPACE file named TestJunit in this file.

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);
   }
}

In C: The JUNIT_WORKSPACE java class file, named TestRunner, to execute the test case.

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());
   }
}   

Step 7: Verify the results

Use the javac compiler to write classes as follows.

C:\JUNIT_WORKSPACE>javac TestJunit.java TestRunner.java

Now run Test Runner to see the results.

C:\JUNIT_WORKSPACE>java TestRunner

Verify the output.

ture