Experiment Seven Web application test _ Write Unit test case, test the DAO layer of user registration function

Source: Internet
Author: User

Package testregister;

Import Java.util.HashSet;

Import Junit.framework.Assert;

Import Org.easybooks.bookstore.dao.IUserDAO;

Import Org.easybooks.bookstore.vo.User;

Import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

public class Testuserdao extends abstractdependencyinjectionspringcontexttests{

The set method of the private variable to inject the bean you want from the ApplicationContext, without the need for an explicit call to Applicationcontext.getbean (XXX)

This class will automatically inject you from the configuration file specified by the Getconfiglocations () method

Private Iuserdao Userdao;

public void Setuserdao (Iuserdao _userdao) {

Userdao=_userdao;

}

@Override

Protected string[] Getconfiglocations () {

Specify spring configuration file Applicationcontext.xml

return new string[] {"Classpath:org/easybooks/bookstore/test/applicationcontext.xml"};

}

Success:

/**

* Test the Register () method in Userdao--registration is successful

*/

public void testregistersuccess () {

User user = New User ("Wzw", "WZW", "Man", 22,new HashSet (0));

Boolean isexit = Userdao.exituser ("WZW");

Assert.assertfalse (Isexit);

Userdao.saveuser (user);

SYSTEM.OUT.PRINTLN ("Registered successfully, the user is:" +user.getusername ());

}

Failed:

/**

* Test the Register () method in Userdao--registration failed

*/

public void Testregisterfail () {

Boolean isexit = Userdao.exituser ("CCJ");

Assert.asserttrue (Isexit);

SYSTEM.OUT.PRINTLN ("registration failed");

}

}

Experiment Seven Web application test _ Write Unit test case, test the DAO layer of user registration function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.