Ember.js 使用Ember 2.7.0在验收测试中模拟服务
对于旧版本的余烬 使用Ember 2.7.0,我无法按照上述答案致电startApp。 然而,经过一些快速测试,这在注入服务时似乎工作得很好Ember.js 使用Ember 2.7.0在验收测试中模拟服务,ember.js,ember-testing,Ember.js,Ember Testing,对于旧版本的余烬 使用Ember 2.7.0,我无法按照上述答案致电startApp。 然而,经过一些快速测试,这在注入服务时似乎工作得很好 import Ember from 'ember'; import { module, test } from 'qunit'; let speakerMock = Ember.Service.extend({ speak: function() { console.log("Acceptance Mock!"); } }); modu
import Ember from 'ember';
import { module, test } from 'qunit';
let speakerMock = Ember.Service.extend({
speak: function() {
console.log("Acceptance Mock!");
}
});
module('Acceptance | acceptance demo', {
beforeEach: function() {
// the key here is that the registered service:name IS NOT the same as the real service you're trying to mock
// if you inject it as the same service:name, then the real one will take precedence and be loaded
this.application.register('service:mockSpeaker', speakerMock);
// this should look like your non-test injection, but with the service:name being that of the mock.
// this will make speakerService use your mock
this.application.inject('controller', 'speakerService', 'service:mockSpeaker');
}
});
test('visit a route that will trigger usage of the mock service' , function(assert) {
visit('/');
andThen(function() {
assert.equal(currentURL(), '/');
});
});
我错过什么了吗?我怀疑:
a) 为什么没有记录?余烬文件
b) 是否因为不鼓励在验收测试中模拟服务?为什么?来自:
验收测试用于测试用户交互和应用程序
流动。测试与应用程序的交互方式与
用户可以通过填写表单字段和单击
按钮。验收测试确保项目中的功能
基本上是功能性的,在确保核心
一个项目的特点没有倒退,项目的目标
我们正在开会
虽然没有“清楚地”提到,但我理解“验收测试的行为与实际应用程序相同”。所以你不应该嘲笑什么。@ykaragol的答案是正确的。一般来说,使用黑盒技术进行验收测试是个好主意。你能澄清一下你想用它实现什么吗?也许我们可以找到一种更合适的方法来实现这一点。这可能是正确的,但在一些重要的情况下,通过一些环境调整,验收测试是可取的。例如,我们使用一个服务进行a/b测试,我们希望将其锁定到一个特定的实验组进行测试。