所以我想知道单元测试在处理外部依赖关系方面是如何工作的.在这里和其他地方,我已经熟悉依赖注入,以及它如何允许我们测试代码的单元(A).但是,我对如何测试现在具有外部依赖性的其他单元(B和C)感到困惑,因此他们可以将它注入原始单元(A).
例如,假设一些类Foo使用外部依赖...
class Foo
{
private ExternalDependency ed;
public int doSomethingWithExternalDependency() {...}
}
Run Code Online (Sandbox Code Playgroud)
而且Bar使用Foo ...
class Bar
{
public int doSomethingWithFoo
{
Foo f = new Foo();
int x = f.doSomethingWithExternalDependency();
// Do some more stuff ...
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我知道我可以使用依赖注入,以便我可以测试Foo,但是我如何测试Bar?我想,我可以再次使用依赖注入,但在某些时候某些单元需要实际创建外部依赖; 那我该怎么测试那个单位呢?
在XCode 4中处理iOS项目时(也许它也在XCode 3中,我只是没有注意到它),在构建设置中有一个名为"Combine High Resolution Artwork"的字段,可以设置为yes或no.
这个设置到底是做什么的?
因此,我将iOS App的描述本地化为多种语言.现在,我想添加一个新版本的应用程序.iTunesConnect似乎要求我为我所描述的每种语言单独输入此文本.
有人知道我是否需要本地化描述?如果我只为每个本地化复制相同的英文文本(不翻译),我的更新会被拒绝吗?
我想要的是能够包装JavaScript属性以修改get/set上的行为.
对于值的属性,我可以执行以下操作:
var obj = {
myProperty : 0
};
function notifyOfChange(obj, propertyName) {
var propertyValue = obj[propertyName];
Object.defineProperty(obj, propertyName, {
get : function() { return propertyValue; },
set : function(newValue) {
var propertyValue = newValue;
console.log("Message from notifyOfChange.");
}
});
};
obj.myProperty = 10; // outputs "Message from notifyOfChange."
Run Code Online (Sandbox Code Playgroud)
但是,如果myProperty已经有一个getter/setter怎么办?
var obj = Object.create({}, {
myProperty : {
get : function() { return this._myProperty; },
set : function(value) {
console.log("Message from obj itself.");
this._myProperty = value;
}, …Run Code Online (Sandbox Code Playgroud)