Example of a DAO layer built with the JUnit Test Spring framework:
Package Com.project.dao;
Import Java.text.DateFormat;
Import Java.text.SimpleDateFormat;
Import java.util.Date;
Import Org.junit.Assert;
Import Org.junit.Test;
Import Org.junit.runner.RunWith;
Import org.springframework.beans.factory.annotation.Autowired;
Import org.springframework.test.context.ContextConfiguration;
Import Org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith (Springjunit4classrunner.class) //cannot be a class other than Powermock, otherwise the spring configuration file cannot be recognized
Contextconfiguration ("File:conf/applicationcontext.xml") //Read Spring configuration file public
class Userdaotest {
@Autowired //Retrieve Applicationcontext.xml, automatically inject the specified bean
Userdao userdao;
@Test public
void Testgetuser () {
int userId = 1;
String nickname = "Nickname 1";
Assert.assertequals (userid, Userdao.getuser (userid). GetUserId ());
Assert.assertequals (nickname, Userdao.getuser (UserId). Getnickname ());
}
}