You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Maven远程运行Jira Script Runner单元测试?

解决方案

1. 确保Maven Surefire插件正确传递系统属性

Script Runner的远程测试依赖baseurl系统属性,必须保证Maven在测试阶段将该属性传递给测试JVM。修改pom.xml中的maven-surefire-plugin配置,显式声明要传递的系统属性:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.2.5</version>
    <configuration>
        <systemPropertyVariables>
            <baseurl>${baseurl}</baseurl>
            <!-- 若需认证,补充账号密码参数 -->
            <username>${jira.username}</username>
            <password>${jira.password}</password>
        </systemPropertyVariables>
    </configuration>
</plugin>

执行测试时在命令行指定参数:

mvn test -Dbaseurl=https://你的Jira实例地址 -Djira.username=你的账号 -Djira.password=你的密码

2. 检查测试类的初始化逻辑

Script Runner的Specification基类会根据baseurl是否存在自动切换本地/远程模式。确保你的测试类没有硬编码强制本地模式的逻辑,比如:

// 错误示例:强制本地模拟,忽略baseurl参数
def setup() {
    useMockResources()
}

正确做法是让基类自动处理,若需自定义初始化,优先判断系统属性:

def setup() {
    if (System.getProperty('baseurl')) {
        // 远程模式逻辑,无需模拟资源
    } else {
        // 本地模式,初始化模拟资源
    }
}

3. 匹配Script Runner测试依赖版本

确保pom.xml中引入的Script Runner测试支持依赖版本与你的Jira实例版本一致:

<dependency>
    <groupId>com.adaptavist</groupId>
    <artifactId>scriptrunner-test-support</artifactId>
    <version>你的Script Runner版本</version>
    <scope>test</scope>
</dependency>

4. 通过Maven Profile隔离本地/远程测试

如果项目包含本地测试用的模拟配置,可通过Profile区分测试场景,避免干扰远程模式:

<profiles>
    <profile>
        <id>remote-test</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <!-- 排除本地测试类(若有) -->
                        <excludes>
                            <exclude>**/*LocalTest.groovy</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

运行时激活远程测试Profile:

mvn test -Premote-test -Dbaseurl=https://你的Jira实例地址

5. 验证Jira实例的可访问性与权限

确认Maven运行环境能正常访问你的Jira实例(无防火墙/代理限制),且使用的账号拥有Script Runner测试所需权限(如创建问题、访问控制台等)。


内容的提问来源于stack exchange,提问作者Yonoss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 22:42:10