???????:
????JDK1.5????(???Junit4?????????????)
??????????
????spring-2.5.jar
????junit-4.4.jar
????spring-test.jar
??????????

 

package user;
import static org.junit.Assert.fail;
import java.util.Date;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.sample.model.user.User;
import com.sample.service.user.IUserService;
/** ????????????????? */
@ContextConfiguration(
locations={
"classpath:spring/persistenceContext.xml"??
"classpath:spring/aopContext.xml"??
"classpath:spring/daoContext.xml"??
"classpath:spring/serviceContext.xml"
}
)
/** ????????????? */
@TransactionConfiguration(defaultRollback = false)
public class UserTest extends AbstractTransactionalJUnit4SpringContextTests{
/** ??????????????? */
@Autowired
private IUserService userService;
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
@Rollback(false)
public void testSaveUser() {
User user=new User();
user.setUsername("zhoujun");
user.setCreatetime(new Date());
userService.saveUser(user);
}
@Test
public void testGetUserById() {
User user=userService.getUserById("1");
System.out.println(user.getUsername());
System.out.println(user.getCreatetime());
}
}