使用Junit进行单元测试,首先引入Junit的jar,配置如下。
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:factory_bean.xml") public class MainApp { @Test public void demon1() { ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"factory_bean.xml"}); Person p1 = context.getBean("chinese",Person.class); System.out.println(p1.sayHello("Marry")); System.out.println(p1.sayGoodBye("Marry")); Person p2 = context.getBean("chinese",Person.class); System.out.println(p2 == p1); System.out.println(context.getBean("&chinese")); } }