无法通过 ANT 运行测试 [英] Not able to run test through ANT

查看:23
本文介绍了无法通过 ANT 运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试类,如果我在 eclipse 中运行,这个类的所有测试都运行良好.(右键单击文件,作为 jUnit 运行)但是当我尝试使用 Ant 脚本运行时它失败了.

I have a test class, all the tests of this class runs fine if I run in eclipse. (right click on the file , run as jUnit) but when I am trying to run using Ant Script it fails.

实际上这个测试是针对 2 个浏览器运行的.此测试在 IE Chrome 上运行良好.它对 IE 运行良好.但是测试无法针对 Chrome 运行.我不确定发生了什么.所有驱动相关信息我都放在项目路径的 allresources/drivers/下.以及我保存在项目的 browserProfiles 文件夹下的浏览器配置文件.

Actually this test is to be run against 2 browsers. This test runs fine against IE Chrome. It runs fine against IE. But test is not able to run against Chrome. I am not sure what's happening. All the driver related information I have placed under allresources/drivers/ of the project path. And browser profiles i have kept under browserProfiles folder of the project.

我不确定为什么无法为 Chrome 进行测试.

I am not sure why tests are not able to be picked up for Chrome.

我附上了测试代码和我试图在源代码中创建 webdriver 和 seldriver 的代码.

I have attached test code and the code where I am trying to create webdriver and seldriver in the source code.

package com.mytests;

public class MyParamTest {
private MyWrapperForBrowser browser;

@Before
public void setup(){
    b = new MyWrapperForBrowser("chrome");
    b.start();
}

@Test
public void testCURDOnEntity() {
    MyEntity e = new MyEntity(browser);
    Assert.assertTrue(e.createMessage("message", "text"));
    // more business logic..
}
}

和源代码

    package com.mysrc;

import java.util.*;
import org.openqa.selenium.*;

public class MyWrapperForBrowser {

    private final WebDriver webDriver;
    private WebDriverBackedSelenium selDriver;


public MyWrapperForBrowser(String driver) {
        if (driver.equalsIgnoreCase("IE")
        {
            // create webDriver , selDriver
        }
        else{

       System.setProperty("webdriver.chrome.driver",
                    "allresources/drivers/chromedriver.exe");
        DesiredCapabilities broserCapabilities = DesiredCapabilities.chrome();
        broserCapabilities.setCapability("chrome.switches", Arrays.asList("--start-minimized"));
        String url = this.getClass().getClassLoader().getResource("browserProfiles/ChromeProfile").getPath()
                .substring(1);
        broserCapabilities.setCapability("chrome.switches",
                Arrays.asList("--user-data-dir=" + url));
        webDriver = new ChromeDriver(broserCapabilities);
        selDriver = new WebDriverBackedSelenium(webDriver, "");
}
}

public void start() {
    webDriver.get(getURL());
    selDriver.windowMaximize();
 }
 }

我在运行 ANT 构建时得到的堆栈跟踪是:

The stack trace which I am getting while running the ANT build is :

[junit] java.util.zip.ZipException: error in opening zip file
[junit]     at java.util.zip.ZipFile.open(Native Method)
[junit]     at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[junit]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[junit]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1028)
[junit]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:147)
[junit]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>

这是构建脚本:

<project name="MyProject" default="build-proj" basedir=".">

    <property file="./build.properties" />

    <path id="project.classpath">   
        <fileset dir="resources/drivers">
            <include name="*.*" />
        </fileset>       
    </path>

    <taskdef resource="emma_ant.properties">
        <classpath>
            <pathelement path="${lib.dir}/emma_ant-2.1.5320.jar" />
            <pathelement path="${lib.dir}/emma-2.1.5320.jar" />
        </classpath>
    </taskdef>

    <target name="build-proj">
        <antcall target="cleanup" />
        <antcall target="compile" />
        <antcall target="test" />
    </target>

    <target name="cleanup" description="clean up">
        <delete dir="${build.dir}" />
        <delete dir="${dist.dir}" />
        <delete dir="${test.report.dir}" />
        <mkdir dir="${build.dir}" />
        <mkdir dir="${build.src.dir}" />
        <mkdir dir="${build.test.dir}" />
    </target>

    <target name="compile" description="compiling all the code">
        <javac srcdir="${src.dir}" destdir="${build.src.dir}" debug="true">
            <classpath>
                <path refid="project.classpath" />
            </classpath>
        </javac>
        <javac srcdir="${test.dir}" destdir="${build.test.dir}" debug="true">
            <classpath>
                <path refid="project.classpath" />
                <path path="${build.src.dir}" />
            </classpath>
        </javac>
    </target>

    <target name="test">
        <junit haltonfailure="false" printsummary="true" fork="true" forkmode="once" >
            <classpath>
                <pathelement path="${src.dir}" />
                <pathelement path="${build.src.dir}" />
                <pathelement path="${build.test.dir}" />
                <pathelement path="${test.data.dir}" />
                <path refid="project.classpath" />
            </classpath>

            <formatter type="xml"/>
            <batchtest todir="${test.report.dir}">
                <fileset dir="${build.test.dir}">
                    <include name="**/*Test.class" />
                </fileset>
            </batchtest>
        </junit>
    </target>
</project>

推荐答案

可能你的类路径不仅包含 .jar 文件.

Probably your classpath contains not only .jar files.

ant 任务junit"只喜欢 .jar 文件(或者我们最好说 Path like结构,在类路径元素中使用 Ant 术语.

The ant task "junit" only likes .jar files (or let's better say Path like structure, to use an Ant term) in the classpath element.

你可以尝试使用

<include name="*.jar" />

代替

<include name="*.*" />

在您的project.classpath"文件集中.

in your "project.classpath"-fileset.

这篇关于无法通过 ANT 运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆