SSM框架单元测试
测试方法一
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:spring/applicationContext-*.xml", "classpath:spring/springmvc.xml" }) public class WebMagicTest { @Autowired private Userservice userservice; @Test public void findUserTest() throws Exception { userservice.findById(1); } }
测试方法二
public class CommonTest { private ApplicationContext applicationContext; @Before public void setUp() throws Exception { applicationContext = new ClassPathXmlApplicationContext(new String[]{"spring/applicationContext-*.xml","spring/springmvc.xml"}); } @Test public void testBeans() throws Exception { String[] list = applicationContext.getBeanDefinitionNames(); for (String str : list) { System.out.println(str); } } }