Create Junit Test cases
Main Class:
package mavenProjectJunitFrameworkTestcase.MavenProjectJunitFrameworkTestcase;
/**
* Hello world!
*
*/
public class App
{
String name;
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
//setName method used to set some value to class variable
public String setName(String name) {
return this.name=name;
}
//sum method is used to calculate sum of two variables
public int sum(int a, int b) {
int c = a+b;
return c;
}
}
Junit Test for Apptest class;
//Generally we junit class with the word 'test' appended to the name of mainclass which we are about to test
package mavenProjectJunitFrameworkTestcase.MavenProjectJunitFrameworkTestcase;
import static org.junit.Assert.*;
import org.junit.Test;
import junit.framework.Assert;
public class Apptest1 {
@Test
public void testSetNameMethod() {
App obj2 = new App();
Assert.assertEquals(obj2.setName("Srikanth"), obj2.name);
}
}
Comments
Post a Comment