我需要在 junit 中创建测试套件报告。当我运行测试套件时,它会正确执行,但是当我运行 build.xml 文件来创建测试套件的 junit 报告时,它不会被创建
代码:
Class first :
public class first extends TestCase{
public static WebDriver driver;
@BeforeClass
public static void testsetup()
{
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
System.out.println("Before class");
driver = new ChromeDriver();
}
@Test
public void testlogin()throws Exception
{
driver.get("URL");
WebElement login = driver.findElement(By.xpath("my xpath");
login.findElement(By.id("username")).sendKeys("username");
login.findElement(By.id("password")).sendKeys("pwd");
driver.findElement(By.xpath("my xpath")).click();
}
@Test
public void testnext()throws Exception
{
//My code
}
@AfterClass
public static void testafterClass()
{
driver.close();
}
第二班:
public class second extends TestCase{
public static WebDriver driver;
@BeforeClass
public static void testsetup()
{
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
System.out.println("Before class");
driver = new ChromeDriver();
}
@Test
public void testlogin()throws Exception
{
driver.get("URL");
WebElement login = driver.findElement(By.xpath("my xpath");
login.findElement(By.id("username")).sendKeys("username");
login.findElement(By.id("password")).sendKeys("pwd");
driver.findElement(By.xpath("my xpath")).click();
}
@Test
public void testnext()throws Exception
{
//My code
}
@AfterClass
public static void testafterClass()
{
driver.close();
}
测试套件代码:
@RunWith(Suite.class)
@SuiteClasses({first.class,second.class})
public class AllTests
{}
构建.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="Section">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="C:/Users/Downloads/eclipse"/>
<property name="junit.output.dir" value="junit"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="Section.classpath">
<pathelement location="bin"/>
<pathelement location="C:/Users/Downloads/selenium4junit-1.5.jar"/>
<pathelement location="../lib/junit-4.11.jar"/>
<pathelement location="../lib/jxl-2.6.jar"/>
<pathelement location="../lib/selenium-java-client-driver-1.0.2.jar"/>
<pathelement location="../lib/selenium-server-standalone-2.31.0.jar"/>
<pathelement location="../lib/xalan-2.7.1.jar"/>
<pathelement location="C:/Users/Downloads/apache-ant-1.9.2/lib/ant-junit.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="Section.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="AllTests">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="Projects.AllTests" todir="${junit.output.dir}"/>
<classpath refid="Section.classpath"/>
</junit>
</target>
<target name="first">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="Projects.first" todir="${junit.output.dir}"/>
<classpath refid="Section.classpath"/>
</junit>
</target>
<target name="second.testnext">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="Projects.second" todir="${junit.output.dir}"/>
<classpath refid="Section.classpath"/>
</junit>
</target>
<target name="second.testlogin">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="Projects.second" todir="${junit.output.dir}"/>
<classpath refid="Section.classpath"/>
</junit>
</target>
<target name="second.testsetup">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="Projects.second" todir="${junit.output.dir}"/>
<classpath refid="Section.classpath"/>
</junit>
</target>
<target name="second">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="Projects.second" todir="${junit.output.dir}"/>
<classpath refid="Section.classpath"/>
</junit>
</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>