Announcement Announcement Module
Collapse
No announcement yet.
Can't Rollback on JUnit Test with Spring Roo (Hibernate + MySQL)? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't Rollback on JUnit Test with Spring Roo (Hibernate + MySQL)?

    Hi guys,

    I have created a Spring Roo Project using Hibernate and MySQL, and some jpa entities.
    This Roo project is a dependency inside another project, and I am trying to create some JUnit tests.
    My Roo project is just for persistence.

    What I would like to have is a rollback after each @Test execution. Is it possible?

    After reading a lot of suggestions I couldn't make any of then work, and my jUnit class is like this right now:
    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @Transactional
    @ContextConfiguration(locations = { "classpath*:spring/*test-context.xml", "classpath*:spring/applicationContext.xml", "classpath*:spring/passport-client-context.xml"})
    public class TaxControllerTest extends AbstractJUnit4SpringContextTests {
    	
    	@Before
    	public void setUp() throws Exception {
    		Tax tax = new Tax();
    		tax.setCode("IPI");
    		tax.persist();
    		tax.flush();
    	}
    
    	@Test
    	public void test1() {
    		assertEquals(1, Tax.countTaxes());
    	}
    
    	@Test
    	public void test2() {
    		assertEquals(1, Tax.countTaxes()); // It fails here, because there is already one, from the first execution.
    	}
    
    }
    Last edited by joaogalli; Nov 30th, 2012, 01:25 PM. Reason: Forgot the AbstractJUnit4SpringContextTests
Working...
X