您的位置:首页 > 编程语言 > Java开发

如何用JUnit4测试spring service

2015-08-05 10:36 495 查看
import static org.junit.Assert.*;

import javax.annotation.Resource;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.syouketu.ssc.common.utils.TestUtils;
import com.syouketu.ssc.enginecompiler.service.IDynamicDeployBeanService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring/application*.xml" })
public class TestDynamicDeployBeanService {

@Resource
ApplicationContext applicationContext;

@Resource
private IDynamicDeployBeanService dynamicDeployBeanService;

@Before
public void setUp() throws Exception {
}

@Test
public void testService() {
try {
String sourceCode = TestUtils.txtString("ITestService.java");
dynamicDeployBeanService.registerComponet(sourceCode);
assertTrue(applicationContext.containsBean("ITestService"));
} catch (Exception e) {
e.printStackTrace();
fail("Test failed!");
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: