- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为了执行自动化 UI 测试,我在 an external cloud service which requires the upload of our test suite 上触发测试(出于这个问题的目的,请考虑给定他们的方法)。
我仍然希望将此过程封装到 JUnit 运行器中,以便与使用不同云服务或本地执行的运行保持一致。我用 Maven 执行我的测试
mvn clean install -Dtest=TestRunner -Dproperties=/path/to/settings.file
而且无论使用哪个测试提供商,我都希望此流程保持一致。
我想出的解决方法是在我的本地机器上触发这样的测试:
@Override
public void run(RunNotifier notifier) {
if (someCondition) {
new DelegateRunner().run(notifier);
} else {
super.run(notifier);
}
}
DelegateRunner
然后调用触发测试的第三方服务在云端。我如何才能将从该服务(我可以查询他们的 API)收到的结果映射回我的本地 JUnit 执行?
RunNotifier
类提供了类似 fireTestFinished
或 fireTestFailure
的方法,但我不确定如何构建对象(Result
, Description
, Failure
) 这些方法作为参数。我怀疑我需要使用测试监听器,但我无法弄清楚细节。
从更广泛的意义上说,当实际测试在远程机器上运行或者甚至不作为 JUnit 测试执行时,我有哪些选择来创建 JUnit 测试结果?这是某人以前遇到过的用例吗?它可能有点异国情调,但我也不认为我是第一个。
首先,我只想提供一个二进制结果——测试通过或至少一个测试失败——以一种不破坏任何 JUnit 集成的方式(如 Maven surefire 插件)。
现在,我得到:
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 501.287 sec
和
No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)
如果测试失败,我如何才能使构建失败并通过其他方式(测试数为 1)?我可以想到一些 hacky 方法,但我确信有一个合适的方法。
最佳答案
在最基本的情况下,只有一个测试结果,DelegateRunner
可能是这样的:
public class DelegateRunner extends Runner {
private Description testDescription = Description
.createTestDescription("groupName", "testName");
public DelegateRunner(Class<?> testClass) {
}
@Override
public Description getDescription() {
return testDescription;
}
@Override
public void run(RunNotifier notifier) {
notifier.fireTestStarted(testDescription);
... trigger remote test ...
if (passed)
notifier.fireTestFinished(testDescription);
else
notifier.fireTestFailure(new Failure(testDescription,
new AssertionError("Details of the failure")));
}
}
然后 getDescription()
和 run()
都需要被包装:
public class FrontRunner extends Runner {
private Runner runner;
public FrontRunner(Class<?> testClass) throws InitializationError {
if (someCondition)
runner = new DelegateRunner(testClass);
else
runner = new JUnit4(testClass);
}
@Override
public Description getDescription() {
return runner.getDescription();
}
@Override
public void run(RunNotifier notifier) {
runner.run(notifier);
}
}
(假设 someCondition
可以预先知道,并且它只是通常需要的默认 JUnit4
运行程序)。
这如期进入 Maven 构建:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running ...FrontRunnerTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.078 sec <<< FAILURE!
testName(groupName) Time elapsed: 0.015 sec <<< FAILURE!
java.lang.AssertionError: Details of the failure
at so.ownrunner.DelegateRunner.run(DelegateRunner.java:28)
at so.ownrunner.FrontRunner.run(FrontRunner.java:27)
at ...
Results :
Failed tests: testName(groupName): Details of the failure
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
然后,如果需要更结构化的响应,Description.addChild()
可用于嵌套套件和/或测试,例如:
public class NestedDelegateRunner extends Runner {
private Description suiteDescription = Description
.createSuiteDescription("groupName");
private Description test1Description = Description
.createTestDescription("groupName", "test1");
private Description test2Description = Description
.createTestDescription("groupName", "test2");
public NestedDelegateRunner(Class<?> testClass) {
suiteDescription.addChild(test1Description);
suiteDescription.addChild(test2Description);
}
@Override
public Description getDescription() {
return suiteDescription;
}
@Override
public void run(RunNotifier notifier) {
notifier.fireTestStarted(test1Description);
notifier.fireTestStarted(test2Description);
notifier.fireTestFinished(test1Description);
notifier.fireTestFailure(new Failure(test2Description,
new AssertionError("Details of the failure")));
}
}
事实上 addChild()
并不重要,但如果没有它,结构可能不太明显 - 例如像 Eclipse 这样的东西只会显示 Unrooted tests
。
关于unit-testing - 手动创建 JUnit Result 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55842745/
我有点困惑为什么在 RoutineRetrieved 函数中分配 ACTIVITYIMAGE 时使用 result.getInt(2) 并在分配 SLOT 时使用 result.getInt(3)..
我是android领域的新手,我想从响应json数组访问每个结果元素,但我无法做到这一点,我试图获取每个元素,但我只得到一个值“rohit1”是第一个元素。请帮助我。 我是 rohit parmar,
我只有从 sql 查询返回的一行 (count(*)),但在执行包时,它向我显示上述错误,并且包失败。 我将结果类型设置为“单行”,并将查询的输出(select count(*) as 'result
我正在尝试使用Diesel将简单的原始SQL转换为MySQL,如本示例所示: https://docs.diesel.rs/diesel/fn.sql_query.html let users = s
我正在尝试 Play 框架的第一个示例,但出现了此错误 在我的路线文件中: # API # ~~~~ GET /api/geotweets/index controllers.api.GeoTw
这段代码可以返回null吗? (this.Result == Result.OK) 此行(或类似行)是否可以返回除 true 或 false 之外的任何内容(例如 null)? 最佳答案 (this.
我有一个 SSIS 执行 SQL 任务。它返回一个完整的结果集(即一个表)。但是,当我执行包时出现以下错误。我已经正确地为返回的结果集命名。 [执行 SQL 任务] 错误:对于完整的结果集和 XML
最近我刚刚将 swift 2.3 项目转换为 3.2,alamofire 也得到了转换,我收到了很多问题,其中大部分都已解决,现在我被给定的两个问题所困扰 问题在 alamofire 的 Respon
我在 R 中收到以下错误消息: Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set", : Unable to r
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。
我正在使用一个简单的命令运行以下存储过程sp_MSforeachdb。我的问题是如何限制结果仅显示至少有 1 条记录满足命令的数据库: 这是我的存储过程: EXECUTE master.sys.sp_
我在单独的线程中运行一些代码: fn f1() -> Result { Err("err1".to_string()) } fn f2() -> Result { Err("err2"
我在这里尝试使用 AsyncTask 从 OWM API 显示 7 天的天气预报。 doInBackground(String...param) 方法也工作正常。我检查了 LOGCAT。 异步完成执行
我已经创建了mysql的索引和全文索引,后端存储引擎是MyISAM。 mysql> show index from play_movie; +------------+------------+---
我有一个表articles,它的结构如下: id, name, date, contents 我有一个表authors,它的结构如下: id, article_id, name, email 一篇文章
我很困惑我们是否应该创建单独的 API 来获取结果和结果计数,或者我们应该只根据结果 API 中的查询字符串来获取计数。 /api/results/ : Fetches all records /ap
我正在制作一个将两个数字相除的系统,如果第二个数字不存在,它将选择第一个数字。这是代码: let new_num: f32 = match num1/num2 { Ok(num) => n
这个问题在这里已经有了答案: Why am I getting "unused Result which must be used ... Result may be an Err variant,
我正在修改 the texture synth 中的示例之一项目: use texture_synthesis as ts; fn main() -> Result { //create a
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: ^ operator in java 我假设 c ^ d是一个类似“的幂”的计算,所以c = 5 , d = 2 ,
我是一名优秀的程序员,十分优秀!