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");
	}
}

相关推荐