使用intellij IDEA从Selenium + JUnit生成ANT结果报告

时间:2014-02-17 05:37:31

标签: java selenium ant junit intellij-idea

我不是ANT的经文,也不是开发工作的新手,我需要为我的测试项目生成某种结果报告(通过/失败)。我使用intellij,selenium web-driver和junit。

我研究这个主题,并且大多数都指向使用ANT生成报告。 但是,大多数例子对我来说都很难理解。我希望有人可以指出我正确的方向,我甚至不确定如何为我的测试用例设置ANT for intellij。

1 个答案:

答案 0 :(得分:4)

我使用ANT在IDE(intellij)中运行我的测试,你可以通过ant运行测试并生成xml / html报告:

 <target name="tests" depends="build">
        <mkdir dir="${junit.output.dir}"/>
        <junit fork="yes" printsummary="withOutAndErr" showoutput="true" outputtoformatters="true" haltonfailure="no"
               failureproperty="test.failed">
            <formatter type="xml"/>
            <test name="com.tests.ExampleTests" todir="${junit.output.dir}"/>
            <classpath refid="seleniumproject.classpath"/>
        </junit>
        <fail message="Test failure detected, check test results." if="test.failed"/>
 </target>

 <target name="junitreport">
    <junitreport todir="${junit.output.dir}">
        <fileset dir="${junit.output.dir}">
            <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="${junit.output.dir}"/>
    </junitreport>
 </target>

我通过Continues Integration或一些.bat文件运行它 我的项目目录

-- Ant
-- MyProject
    -- test
    -- build.xml
    -- run-test.bat
    -- run-tests-unx.sh

来自.bat文件的脚本:

@echo OFF
color 0a
echo:
echo Test is Running...
echo:
echo Run all selenium tests
echo Working directory: %~dp0
echo:
echo:
set LOG=Rebuild.log
%~dp0..\ant\bin\ant.bat tests -buildfile %~dp0build.xml -logfile %LOG%

unix .sh的脚本:

#! /bin/bash
echo "Test is Running...";
dir=$(pwd);
echo $dir;
cd ..
echo ${PWD}
dir2=$(pwd);
cd $dir;
$dir2/ant/bin/ant tests -buildfile $dir/build.xml -logfile $dir/Rebuild.log

您可以浏览cmd:

/ant/bin/ant.bat [your target name] -buildfile [your build.xml]

Ant会生成这样的东西(junit-reports): junit reports

您将打开index.html以查看结果:

junit resutls