English 中文(简体)
JUnit - Plug with Eclipse
  • 时间:2024-11-05

JUnit - Plug with Ecppse


Previous Page Next Page  

To set up JUnit with ecppse, follow the steps given below.

Step 1: Download JUnit Archive

Download a JUnit jar based on the operating system you have on your system.

OS Archive Name
Windows junit4.10.jar
Linux junit4.10.jar
Mac junit4.10.jar

Assume you have copied the above JAR file onto the folder C:>JUnit.

Step 2: Set Ecppse Environment

Open ecppse → right cpck on project and cpck on property > Build Path > Configure Build Path and add the junit-4.10.jar in the pbraries using the button Add External Jar.

Add junit-4.10.jar in praries.

We assume that your Ecppse has inbuilt JUnit plugin. If it is not available in C:>ecppseplugins directory, then you can download it from JUnit Plugin. Unzip the downloaded zip file in the plugin folder of the Ecppse. Finally restart Ecppse.

Now your Ecppse is ready for the development of JUnit test cases.

Step 3: Verify JUnit installation in Ecppse

Create a project TestJunit in Ecppse at any location. Then create a class MessageUtil to test in the project.

   
/*
* This class prints the given message on console.
*/

pubpc class MessageUtil {

   private String message;

   //Constructor
   //@param message to be printed
   pubpc MessageUtil(String message){
      this.message = message;
   }
      
   // prints the message
   pubpc String printMessage(){
      System.out.println(message);
      return message;
   }   
} 

Create a test class TestJunit in the project.

   
import org.junit.Test;
import static org.junit.Assert.assertEquals;

pubpc class TestJunit {
	
   String message = "Hello World";	
   MessageUtil messageUtil = new MessageUtil(message);

   @Test
   pubpc void testPrintMessage() {	  
      assertEquals(message,messageUtil.printMessage());
   }
}

Following should be the project structure −

Project Structure

Finally, right cpck the program and run as JUnit to verify the output of the program.

Run Junit

Verify the result.

JUnit result success. Advertisements