Skip to Content
Quick Start

1 Setting the classpath in the Web Application Server.
2 Write a class that extends the junit.framework.TestCase class.
3 Add a testMethod to your TestCase class.
4 Writing a test methods for the TestCase.
5 Writing a assertEquals for the testmethods.
6 Write new tests and repeat until all program requirements are met and all tests pass.
7 Running the Test using Junit.

Setting the classpath in the Web Application Server
Go to Java Perspective and create a java project

image

Next go to Java Build path and the junit.jar files
From(SAP – Home)Dir:/Program Files/SAP/JDT/eclipse/plugins/org.junit._3.8.1

image

image

Writing a TestCase

testMethodName

Each unit test will be implemented as a method with the name testXxxxx, where Xxxxx is as descriptive a name as you can provide. Effective tests will test a desired outcome and behavior of a class. This is usually done via the assertEquals( v1, v2 ) message.

assertEquals

The TestCase class contains several overloaded versions of the assertEquals method. This method is used to confirm that each action produces the correct results.

Creating a class File with the TestCase, test methods and assertEquals

image

TestRunner

TestRunner is the Java program that will systematically run each of the testMethods that you wrote in your TestXxxxx class. It will also automatically track and report the successes and failures recorded. The console version is good, but the graphic versions allow you to see a GREEN BAR when all tests pass. If any test fails, you will see a RED BAR instead. This visual information regarding the successes and failures of your implementation is not only useful, it is great fun to see.
Now Run the TestCase it can be tested either the complete project or for the Single TestCase.

image

Creating a New test Application for junit

image

Select the corresponding project

image

Next Select the TestCase(We can also select the entire project)

image

Green Bar is shown if the TestCase is ok and Red Bar is shown if the TestCase fails.

Success Test Case

image

Failure Test Case

image

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply