使用JenkinsRule类构建Jenkins插件测试

时间:2013-09-03 04:53:55

标签: java junit jenkins jenkins-plugins

我正在尝试使用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();

  }
}

根据示例https://wiki.jenkins-ci.org/display/JENKINS/Unit+Test

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

1 个答案:

答案 0 :(得分:2)

好吧好像我的pom.xml已经过时了

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

这是可行的

相关问题