2014-02-17 74 views
1

我不是ANT的經文,也是開發工作的新手,我需要爲我的測試項目生成某種結果報告(通過/失敗)。我使用intellij,selenium web-driver和junit。使用intellij從Selenium + JUnit生成ANT結果報告IDEA

我對這個主題進行了研究,並且最重視使用ANT來生成報告。然而,大多數例子對我來說都很瞭解。我希望有人能指出我正確的方向,我甚至不確定如何爲我的測試案例設置ANT for intellij。

回答

4

我用ANT與IDE出來(的IntelliJ)運行我的測試,你可以通過螞蟻運行測試和生成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> 

我運行它通過整合繼續或某些.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的報告): junit reports

您將打開指數。 html看到結果:

junit resutls

+0

謝謝安德魯! 對於任何需要構建ANT xml的intellij用戶, 構建>生成ANT構建(選擇名稱和常規配置) 現在,您可以將junit報告代碼添加到xml中 – user2853922

相關問題