How is an integration testing properly done with hibernate 3 spring 3.0.5 with spring transaction management(maven project)?

Don't auto wire the user objects create then in the setup method.

Don't auto wire the user objects create then in the setup method. If you add @Transactional annotation to the test class - spring will start a transaction before running the test (& setup method)- run the test as a part of the transaction and then rollback the transaction. This way you don't have to write code in the tearDown method to explicitly delete the objects(undo things done in the setup).

You will have to call flush / clear on the session - by getting a reference to SessionFactory injected into the test to force the queries to be fired & the object re-fetched from the database.

Sorry for the delay, I know get what you are trying to say. I must admit it's not clear enough. You said ".

This way you don't have to write code in the tearDown method to explicitly delete the objects(undo things done in the setup). " that means creating new object for and inside each test? – black sensei Mar 31 at 18:32.

Just make it simple buddy @Autowired private UserDAO userDao; private User user1; private User user2; @Before public void setUp() { user1 = new User(); user1. SetEmail("user1@somemail. Com"); user1.

SetPassword("mypass"); user1. SetUsername("user1"); user2 = new User(); user2. SetEmail("[email protected]"); user2.

SetPassword("password"); user2. SetUsername("user2"); } It would be better if put create user the test method @Test public void testGetUser() { userDao. Create(user1); User expResult = user1; User result = userDao.

GetUser(user1.getId()); Assert. AssertEquals(expResult.getId(), result.getId()); Assert. AssertEquals(expResult.getEmail(), result.getEmail()); } You can add @TransactionConfiguration to rollback your transaction such as Create Update Delete operation.

@RunWith(SpringJUnit4ClassRunner. Class) @ContextConfiguration({"classpath:WEB-INF/testadmin-webapp-config. Xml"}) @TransactionConfiguration(defaultRollback=true).

Thanks for the example adisembiring, really appreciate it. I do have one question, though, how would you test for collections say, testGetAll() how to provide data in the database before testing that one. In fact that's one of the reason why I save some of the test objects in the setUp() method and clear them in the teardown.

Thanks again – black sensei Apr 3 at 17:10 put userDao. Create(user1); in the body at test method, and then use your dao to find user by the user id. You ca use @TransactionConfiguration(defaultRollback=true) to rollback user that you save, It will return your database in the first state before you run the test.So you doesn't need to use tearDown to remove user – Adi Sembiring Apr 4 at 1:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions