使用JenkinsRule类构建Jenkins插件测试

4

我正在尝试使用JenkinsRule对Jenkins插件进行单元测试

所有的测试都建议采用这种方法

package hudson.plugins.xxxx;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.tasks.Shell;
import org.junit.*;
import org.jvnet.hudson.test.JenkinsRule;

public class Apptest{

  @Rule public JenkinsRule jenkinsRule = new JenkinsRule();

  @Test public void first() throws Exception {
    FreeStyleProject project = jenkinsRule.createFreeStyleProject();
    project.getBuildersList().add(new Shell("echo hello"));
    FreeStyleBuild build = project.scheduleBuild2(0).get();

  }
}

根据示例

但是jenkinsRule.createFreeStyleProject()是受保护的方法,不允许我调用它。我应该如何测试构建器

1个回答

2

好的,看起来我的pom.xml文件已经过期了。

<parent>
    <groupId>org.jenkins-ci.plugins</groupId>
    <artifactId>plugin</artifactId>
    <version>1.499</version>
</parent>

这是一个有效的例子


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接