【问题标题】:Exception while executing integration tests in maven在 Maven 中执行集成测试时出现异常
【发布时间】:2015-02-17 19:49:28
【问题描述】:

使用 mvn verify 对我的 webapp 执行集成测试时出现以下异常。集成测试只是使用 HtmlUnit 加载服务器 url 并检查状态代码 200。不确定我在这里缺少什么。看起来资源过滤在这里没有按预期工作。请指导。

错误日志:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.study.jenkins.it.htmlunit.PageIT
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.951 sec <<< FAILURE! - in com.study.jenkins.it.htmlunit.PageIT
testScenario(com.study.jenkins.it.htmlunit.PageIT)  Time elapsed: 0.949 sec  <<< ERROR!
java.net.MalformedURLException: no protocol: ${server.url}
        at java.net.URL.<init>(URL.java:585)
        at java.net.URL.<init>(URL.java:482)
        at java.net.URL.<init>(URL.java:431)
        at com.gargoylesoftware.htmlunit.util.URLCreator.toNormalUrl(URLCreator.java:36)
        at com.gargoylesoftware.htmlunit.util.URLCreator$URLCreatorStandard.toUrlUnsafeClassic(URLCreator.java:82)
        at com.gargoylesoftware.htmlunit.util.UrlUtils.toUrlUnsafe(UrlUtils.java:195)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:359)
        at com.study.jenkins.it.htmlunit.PageIT.testScenario(PageIT.java:12)

Running com.study.jenkins.it.selenium.PageIT

pom.xml

<properties>
    <dev.tc.base.url>http://dev-server.com</dev.tc.base.url>
    <tst.tc.base.url>http://tst-server.com</tst.tc.base.url>
</properties>

<build>
    <finalName>${project.artifactId}</finalName>
    <resources>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <server.url>${dev.tc.base.url}/cicd-demo/</server.url>
        </properties>
    </profile>
    <profile>
        <id>tst</id>
        <properties>
            <server.url>${tst.tc.base.url}/cicd-demo/</server.url>
        </properties>
    </profile>
</profiles>

src/test/resources/url.properties

server.url=${server.url}

【问题讨论】:

  • 不是 Maven 专家。但从堆栈跟踪的外观来看,它无法将 ${server.url} 值替换为您的 http url 到 dev 或 tst 服务器。
  • 你为什么期望 maven 只是将属性文件中的键替换为系统参数中的值
  • 我正在尝试在不同的环境上运行集成测试。值得一提的是,当我将 url.properties 和 xpath.properties 都移动到 src/main/resources 并将元素更新到 src/main/resources 时,事情开始按预期工作。跨度>

标签: java maven maven-profiles maven-resources-plugin


【解决方案1】:

通过测试资源找到了过滤问题的解决方案。

替换

 <resources>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

<testResources>
    <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
    </testResource>
</testResources>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 2012-10-24
    • 1970-01-01
    相关资源
    最近更新 更多