java - Unit Testing a controller -


there project turnover me, task make unit test controller. i've tried search tutorials net, method controller found:

1. http://developer.teradata.com/viewpoint/reference/viewpoint-pdk-cookbook/how-to-create-unit-tests-for-controllers
2. http://www.java-tutorial.ch/software-testing/easymock-tutorial

links above doesn't fill glass. i'm new unit testing, below method controller

controller:

 private boolean insertnewuser( string name, string username, string password, string email, string usertype,                                    string team, string[] projectid,httpsession session )     {         usersdao usersdao = new usersdao();         arraylist<integer> projects = new arraylist<integer>();         boolean insert;          string sessiontype = ( string ) session.getattribute( sessionutility.session_type );         if( sessiontype.equalsignorecase( sessionutility.type_superadmin ) )         {             if( usertype.equalsignorecase( sessionutility.type_admin ) ||                 usertype.equalsignorecase( sessionutility.type_superadmin ) )             {                 if( projectid != null )                 {                     for( int = 0; < projectid.length; i++ )                     {                         projects.add( integer.parseint( projectid[i] ) );                     }                 }             }             }         if( !projects.contains( integer.parseint( ( string ) session.getattribute( sessionutility.session_project ) ) ) )         {             projects.add( integer.parseint( ( string ) session.getattribute( sessionutility.session_project ) ) );         }         insert = usersdao.insertnewuser( name, username, password, email, usertype, team, projects );          return insert;      } 

question: how make unit test controller? example method above.

if need more clarification please comment.

update: easymock example great

you make use of spring's unit testing , create (http://static.springsource.org/spring-batch/reference/html/testing.html):

import static org.junit.assert.*;      @before     private void setup(){         //init variables here     }      @test     private boolean insertnewuser(){ //initialize variables:   string name, string username, string password, string email, string usertype,   string team, string[] projectid,httpsession session ;          string sessiontype = ( string ) session.getattribute( sessionutility.session_type );         assertequals(sessiontype, sessionutility.type_superadmin);         assertequals(usertype, sessionutility.type_admin);         assertequals(usertype, sessionutility.type_superadmin);         assertnotnull(projectid);      } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -