HSFUnit实现单元测试

来源:互联网 发布:淘宝的折800不计销量吗 编辑:程序博客网 时间:2024/06/06 05:36

1.使用原因

         hsf的使用一般是在web应用中,但是如果只是想测试远程服务是否正确,就没有必要每次都打war包,这样比较麻烦。

         所以需要直接在Junit中直接测试


2.使用

         (1)添加依赖

<dependency><groupId>com.taobao.hsf</groupId><artifactId>hsfunit</artifactId><version>1.0.6</version><scope>test</scope></dependency>

         (2)编写测试代码

@Testpublic void test() {//必须放在第一句//第一个参数指定hsf所在路径,第二个参数表示版本号HSFEasyStarter.start("d:/hsf/", "1.4.9.5");ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");HelloWorldService service = (HelloWorldService) ctx.getBean("HelloWorldConsumer");//必须写上,因为需要等待服务发布ServiceUtil.waitServiceReady(service);String result = service.sayHello("cpf");System.out.println(result);}


1 0
原创粉丝点击