Spring集成junit
package junit; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.test.annotation.Repeat; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.test.context.transaction.TransactionalTestExecutionListener; import org.springframework.transaction.annotation.Transactional; @ContextConfiguration({ "classpath:spring-beans.xml", "classpath:spring-jpa.xml" }) @TransactionConfiguration(defaultRollback = false) @TestExecutionListeners({ TransactionalTestExecutionListener.class }) @Transactional public class TestTemplate extends AbstractJUnit4SpringContextTests { @BeforeClass public static void beforeClass() { System.out.println("@BeforeClass"); } @BeforeTransaction public void beforeTx() { System.out.println("@BeforeTransaction"); } @Before public void before() { System.out.println("@Before"); } @Test @Repeat(1) public void test() { System.out.println("@Test"); } @After public void after() { System.out.println("@After"); } @AfterTransaction public void afterTx() { System.out.println("@AfterTransaction"); } @AfterClass public static void afterClass() { System.out.println("@AfterClass"); } }
相关推荐
shirleypaddy 2020-10-19
qingmumu 2020-10-19
lustdevil 2020-10-18
ganlulululu 2020-10-12
lustdevil 2020-08-03
lustdevil 2020-07-18
lustdevil 2020-06-25
lustdevil 2020-06-21
zhengzf0 2020-06-21
宿命java 2020-06-15
JackYin 2020-06-14
dongxurr 2020-06-07
snowphy 2020-06-06
zhengzf0 2020-05-28
81901836 2020-05-26
Julywhj 2020-05-26