Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
b3bb235d
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b3bb235d
编写于
5月 29, 2014
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added RestartableJenkinsRule to test Jenkins across restarts
上级
2edf25a2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
104 addition
and
0 deletion
+104
-0
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
+1
-0
test/src/main/java/org/jvnet/hudson/test/RestartableJenkinsRule.java
...in/java/org/jvnet/hudson/test/RestartableJenkinsRule.java
+103
-0
未找到文件。
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
浏览文件 @
b3bb235d
...
...
@@ -222,6 +222,7 @@ import org.xml.sax.SAXException;
* @see <a href="http://wiki.jenkins-ci.org/display/JENKINS/Unit+Test">Wiki article about unit testing in Jenkins</a>
* @author Stephen Connolly
* @since 1.436
* @see RestartableJenkinsRule
*/
@SuppressWarnings
({
"deprecation"
,
"rawtypes"
})
public
class
JenkinsRule
implements
TestRule
,
MethodRule
,
RootAction
{
...
...
test/src/main/java/org/jvnet/hudson/test/RestartableJenkinsRule.java
0 → 100644
浏览文件 @
b3bb235d
package
org.jvnet.hudson.test
;
import
groovy.lang.Closure
;
import
org.junit.rules.MethodRule
;
import
org.junit.rules.TemporaryFolder
;
import
org.junit.runner.Description
;
import
org.junit.runners.model.FrameworkMethod
;
import
org.junit.runners.model.Statement
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Provides a pattern for executing a sequence of steps.
* In between steps, Jenkins gets restarted.
*
* <p>
* To use this, add this rule instead of {@link JenkinsRule} to the test,
* then from your test method, call {@link #step(Closure)} or {@link #addStep(Statement)} repeatedly.
*
* <p>
* The rule will evaluate your test method to collect all steps, then execute them in turn and restart
* Jenkins in between.
*
* @author Kohsuke Kawaguchi
* @see JenkinsRule
* @since 1.567
*/
public
class
RestartableJenkinsRule
implements
MethodRule
{
public
JenkinsRule
j
;
private
Description
description
;
private
final
List
<
Statement
>
steps
=
new
ArrayList
<
Statement
>();
private
TemporaryFolder
tmp
=
new
TemporaryFolder
();
/**
* Object that defines a test.
*/
private
Object
target
;
/**
* JENKINS_HOME
*/
public
File
home
;
@Override
public
Statement
apply
(
final
Statement
base
,
FrameworkMethod
method
,
Object
target
)
{
this
.
description
=
Description
.
createTestDescription
(
method
.
getMethod
().
getDeclaringClass
(),
method
.
getName
(),
method
.
getAnnotations
());
this
.
target
=
target
;
return
tmp
.
apply
(
new
Statement
()
{
@Override
public
void
evaluate
()
throws
Throwable
{
// JENKINS_HOME needs to survive restarts, so we'll allocate our own
home
=
tmp
.
newFolder
();
// test method will accumulate steps
base
.
evaluate
();
// and we'll run them
run
();
}
},
description
);
}
public
void
step
(
final
Closure
c
)
{
addStep
(
new
Statement
()
{
@Override
public
void
evaluate
()
throws
Throwable
{
c
.
call
(
j
);
}
});
}
public
void
addStep
(
final
Statement
step
)
{
steps
.
add
(
new
Statement
()
{
@Override
public
void
evaluate
()
throws
Throwable
{
j
.
jenkins
.
getInjector
().
injectMembers
(
step
);
j
.
jenkins
.
getInjector
().
injectMembers
(
target
);
step
.
evaluate
();
}
});
}
private
void
run
()
throws
Throwable
{
HudsonHomeLoader
loader
=
new
HudsonHomeLoader
()
{
@Override
public
File
allocate
()
throws
Exception
{
return
home
;
}
};
// run each step inside its own JenkinsRule
for
(
Statement
step
:
steps
)
{
j
=
new
JenkinsRule
().
with
(
loader
);
j
.
apply
(
step
,
description
).
evaluate
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录