Junit Mockito example
//Mainclass: App //We will mock the setName method in App class using Mockito package mavenProjectJunitFrameworkTestcase.MavenProjectJunitFrameworkTestcase; 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 AppTest class: package mavenProjectJunitFrameworkTestcase.MavenProjectJunitFrameworkTestcase; import static org.junit.Assert.*; import org.junit.Test; import org.mockito.Mockito; import junit.framework.Asse...
Comments
Post a Comment