idea junit插件、junit集成ant脚本

1 idea JunitGenerator 插件

  • 插件的安装
    在idea plugin中搜索JunitGenerator2.0 并安装


    Paste_Image.png
Paste_Image.png
Paste_Image.png
  • 自动生成测试类
    在编辑页面右键点击Generater或使用快捷键Alt+Insert,选择junittest自动生成,一般选择junit4
Paste_Image.png
Paste_Image.png

2 ant中实现打包前的自动测试

我们在原来的ant脚本中编译之后,打包之前,增加一个新的target,取个名字叫junit

<target name="junit" depends="compile">
        <junit printsummary="true">

            <classpath refid="lib-classpath"/>
            <formatter type="xml"/>
            <batchtest todir="${dist.dir}/xml">
                <fileset dir="${dist.dir}/class">
                    <include name="**/*Test.class"/>
                </fileset>
            </batchtest>
        </junit>
        <junitreport todir="${dist.dir}/report">
            <fileset dir="${dist.dir}/xml">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${dist.dir}/report"/>
        </junitreport>
    </target>

需要注意几点:

  • 需要在lib目录下增加junit.jar、hamcrest-core-.jar 和hamcrest-library-.jar,不然会报找不到类的错误
  • 需要在ant脚本的int阶段,相应的创建xml目录和report目录
  <!-- 初始化,建立目录,复制文件 -->
    <target name="init" depends="clean" description="初始化,建立目录">
        <mkdir dir="${dist.dir}"/>
        <mkdir dir="${dist.dir}/class"/>
        <mkdir dir="${dist.dir}/src"/>
        <mkdir dir="${dist.dir}/report"/>
        <mkdir dir="${dist.dir}/xml"/>
    </target>

运行ant脚本,效果如下

Paste_Image.png
  • 在out目录下生成的文件结构如下:
Paste_Image.png
  • 在report目录下,用浏览器打开index.xml文件,效果如下:
Paste_Image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,148评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,092评论 19 139
  • 一、ant安装 $su root$vi /etc/bashrc插入两行(i+enter插入)export ANT_...
    ss酱阅读 5,879评论 25 18
  • 吾祖王济,颇善弓马,曾于洛中买地为马埒,编钱满之,时人谓为“金沟”。一日与王恺赌射于之,以名牛“八百里驳”为注。恺...
    螺旋真理阅读 2,875评论 0 1
  • 道可道,非常道,价值投资乃正道。 投资也是道德经在金融生活中的反映。 投机的那叫零和博弈,而价值投资是世界观的一种...
    cuttie_jing阅读 4,849评论 0 1

友情链接更多精彩内容