Here following is the class to be tested using JUnit
public class MyClass {
public int add(int a,int b){
return a+b;
}
public int sub(int a,int b){
return a-b;
}
public int mul(int a,int b){
return a*b;
}
public int div(int a,int b){
return a/b;
}
}
class that contains three testing method to test add method of class MyClass
import static org.junit.Assert.assertEquals;
import org.junit.*;
public class MyClassTest {
@Test
public void add() {
MyClass c=new MyClass();
assertEquals(30, c.add(10,20));
}
@Test
public void add2() {
MyClass c=new MyClass();
assertEquals(310, c.add(10,20));
}
@Test
public void add3() {
MyClass c=new MyClass();
assertEquals(30, c.add(10,20));
}
public static void main(String args[]) {
org.junit.runner.JUnitCore.main("MyClassTest");
}
}
Now set junit-4.5.jar into classpath , compile and run .
similarly you can write test cases for other methods.
Subscribe to:
Posts (Atom)
Popular Posts
-
HSQLDB is a portable RDBMS implemented in pure java. It can be embedded with your application as well as can be used separately. It is very ...
-
If you want to use the database into your web application, you can use the HSQLDB in In_Process mode. In this mode, you can embed the HSQLD...
-
HTML Page < html > < head > < title > welcome </ title > < script language = "javascript"...
-
In web application ApplicationContext is created using Context Loaders. there are two implementations of context loader. ContextLoaderLis...
-
HSQLDB database it a very small database that can be controlled from you application. you can start and stop the database by writing the ...
-
JSP code <%@page import="java.sql.*"%> <%! int prod_id=1; String prod_name="Laptop"; int qty=2; float p...
-
Some time you will see the form containing the button " Add More " . This facility is provided for the user to get the values ...
-
StudentRegistration │ index.html │ login.html │ └───WEB-INF │ web.xml │ └───classes login.class lo...
-
package process; import javax.swing. * ; import javax.swing.table. * ; import java.sql. * ; /** * This class create JTable from Da...
-
Hibernate ORM framework does not provide any approch to connect to MS Access database. Unfortunately, Access is not supported officially...