搭建Spring环境(自行搭建):
@RunWith注解指定使用springJunit的测试运行器
@ContextConfiguration注解指定测试用的spring配置文件的位置
import static org.junit.Assert.*;
import javax.annotation.Resource;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class test
{
@Resource
RelationEventDao an;
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
System.out.println("setUpBeforeClass");
}
@AfterClass
public static void tearDownAfterClass() throws Exception
{
System.out.println("tearDownAfterClass");
}
@Before
public void setUp() throws Exception
{
System.out.println("setUp");
}
@After
public void tearDown() throws Exception
{
System.out.println("tearDown");
}
@Test
public void testTest()
{
try
{
assertNotNull(an.Event("测试的事件"));
}
catch (ZhiWeiException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}