分享

easyb的使用

 昵称5150925 2011-06-29

easyb 是基于GroovyDSLDomain Specific Languages领域定义语言)实现的可适用于JavaGroovy的测试框架。它提供了对AntMaven的支持来执行stories测试。

 

它的目的就是: 让我们的单元测试跟接近于业务语言,为此他提供了三个关键字:given, when, then。见名知义,given是提供一个上下文,when是提供一个业务场景,then是执行一些断言。

Ant运行easyb

 

1.         首先需要从官方下载easyb发布包,它包括commons-cli-VERSION.jar, easyb-VERSION.jar, groovy-VERSION.jar,将这些依赖引入到你的项目lib文件夹中。

2.         编写业务接口和实现类,Java代码如下可参考。
 

3.         定义build.xml,启动easybXml代码如下,可参考。
 

从上面的XML文件中我们可以看到easyb首先在ANT中注册它的Task,然后调用easyb,测试用例由*Story.groovy或者*.story提供,report生成报告,支持多种格式输出。

4.         下面看看easyb的魔力所在:Groovy代码如下,可参考。
 

5.         上面的测试利用了easyb的三个关键词,模拟了一系列业务场景和断言。我们运行ANT(打开Ant视图或者在build.xml 文件上右击,run as),可以得到这样的运行结果,文本信息代码如下:

Buildfile: D:\talendProgramWorkspace\EasybDemo\build.xml

init:

   [delete] Deleting directory D:\talendProgramWorkspace\EasybDemo\target

all:

    [mkdir] Created dir: D:\talendProgramWorkspace\EasybDemo\target

    [easyb] easyb is preparing to process 3 file(s)

    [easyb] Running hello service story (HelloService.story)

    [easyb] Scenarios run: 1, Failures: 0, Pending: 0, Time elapsed: 0.593 sec

    [easyb] Running IO service story (IOService.story)

    [easyb] Scenarios run: 2, Failures: 0, Pending: 0, Time elapsed: 0.079 sec

    [easyb] Running login service test story (LoginServiceTest.story)

    [easyb] Scenarios run: 3, Failures: 0, Pending: 0, Time elapsed: 0.156 sec

    [easyb] 6 total behaviors ran with no failures

    [easyb] easyb execution passed

BUILD SUCCESSFUL

Total time: 2 seconds

Command line运行easyb

 

%Project Path %>java -cp lib\easyb-0.9.8.jar;lib\commons-cli-1.2.jar;lib\groovy-all-1.7.5.jar;bin\ org.easyb.BehaviorRunner bin\LoginServiceTest.story bin\HelloService.story bin\IOService.story

 

%easyb_home%>java -cp easyb-0.9.8.jar;lib\commons-cli-1.2.jar;lib\groovy-all-1.7.5.jar org.easyb.BehaviorRunner Noname.specification

 

Colored command line output

% Project Path %>java -cp lib\easyb-0.9.8.jar;lib\commons-cli-1.2.jar;lib\groovy-all-1.7.5.jar;bin\ org.easyb.BehaviorRunner bin\LoginServiceTest.story bin\HelloService.story bin\IOService.story -prettyprint

 

easyb plug-in for Eclipse 运行easyb

 

1、  Eclipse中更新Easybplug-in(Help->Install New Software...)

         Groovyhttp://dist./release/GRECLIPSE/e3.5/

         Easybhttp://easyb./svn/trunk/eclipse-plugins/org.easyb.eclipse.updatesite/

2、  创建Java ProjectAdd Easyb Libraries (Right-click Java Project->build path-> Add Libraries ->User Library->new &Add Jars…)

3、  编写业务接口和实现类。

4、  创建easyb storyRight-click Java Project->other->Easyb中的Storyfinish

5、  story中编写测试用例,Right-click story->Run as->Behaviour,即可运行easyb

 

或者

创建Groovy Project,编写业务接口和实现类。创建easyb storyRight-click Java Project->other->Easyb中的Storyfinish。在story中编写测试用例,Right-click story->Run as->Behaviour,即可运行easyb

Modify maven repository path

1%MAVEN_HOME%\conf\settings.xml

<settings> 

   <!-- localRepository 

   | The path to the local repository maven will use to store artifacts. 

   | Default: ~/.m2/repository 

   <localRepository>/path/to/local/repo </localRepository> 

   -->

       <localRepository>D:\Java\MavenRepo</localRepository>  

   ...

</settings>

 

2eclipse->window->preferences->maven->user setting (%MAVEN_HOME%\conf\settings.xml).

Maven运行easyb:

Maven jar包安装只需执行一次即可。第3步只执行一次即可

 

1.创建maven工程:%Workspace%>mvn archetype:create -DgroupId=com.test -DartifactId=EasybMvnDemo

2maven工程转化为eclipse工程:%ProjectPath%>mvn eclipse:eclipse

3.安装jar

         %DfilePath%>mvn install:install-file -DgroupId=org.easyb -DartifactId=maven-easyb-plugin -Dversion=0.9.7-1 -Dpackaging=jar -Dfile=maven-easyb-plugin-0.9.7-1.jar

         %DfilePath%>mvn install:install-file -DgroupId=org.easyb -DartifactId=easyb -Dversion=0.9.7 -Dpackaging=jar -Dfile=easyb-0.9.7.jar

4.导入该eclipse工程。

5.在src/main/java下面的com.test包中编写接口和实现类

src\test\easyb下面编写storyspecification文件即可

Dependencymaven-easyb-plugin.jar 需写入pom.xml文件。

6Project Pom.xml

Basic Configuration

  <dependencies>

    <dependency>

      <groupId>org.easyb</groupId>

      <artifactId>maven-easyb-plugin</artifactId>

      <version>0.9.7-1</version>

      <scope>test</scope>

    </dependency>

  </dependencies>

  <build>

    <plugins>

      <plugin>

        <groupId>org.easyb</groupId>

        <artifactId>maven-easyb-plugin</artifactId>

        <version>0.9.7-1</version>

        <executions>

          <execution>

            <goals>

              <goal>test</goal>

            </goals>

          </execution>

        </executions>

      </plugin>

    </plugins>

  </build>

Customized Directories

  <build>

    <plugins>

      <plugin>

        <groupId>org.easyb</groupId>

        <artifactId>maven-easyb-plugin</artifactId>

        <version>0.9.7-1</version>

        <executions>

          <execution>

            <goals>

              <goal>test</goal>

            </goals>

          </execution>

        </executions>

        <configuration>

          <easybTestDirectory>${basedir}/src/test/stories</easybTestDirectory>

          <storyReport>${project.build.directory}/easyb-stories.txt</storyReport>

          <xmlReport>${project.build.directory}/easyb-report.xml</xmlReport>

        </configuration>

      </plugin>

    </plugins>

  </build>

Creating HTML story reports

  <build>

    <plugins>

      <plugin>

        <groupId>org.easyb</groupId>

        <artifactId>maven-easyb-plugin</artifactId>

        <version>0.9.7-1</version>

        <executions>

          <execution>

            <goals>

              <goal>test</goal>

            </goals>

          </execution>

        </executions>

        <configuration>

<easybTestDirectory>${basedir}/src/test/stories</easybTestDirectory>

          <storyType>html</storyType>

          <storyReport>${project.build.directory}/easyb/stories.html</storyReport>

        </configuration>

      </plugin>

    </plugins>

  </build>

Running stories with specific tags

 

Tags can be activated via the 'easyb.tags' command line flag (e.g. "-Deasyb.tags='runme,metoo'") or by configuring them in the pom.xml:

 

 

  <build>

    <plugins>

      <plugin>

        <groupId>org.easyb</groupId>

        <artifactId>maven-easyb-plugin</artifactId>

        <version>0.9.7-1</version>

        <executions>

          <execution>

            <goals>

              <goal>test</goal>

            </goals>

          </execution>

        </executions>

        <configuration>

            <tags>runme,metoo</tags>

        </configuration>

      </plugin>

    </plugins>

  </build>

 

 

 

参考网址

 

http://www./

 

http://www./maven-easyb-plugin/

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多