我正在学习单元测试,并且正在努力学习一些可能非常基本的概念.假设我有两种方法.
方法A将文件作为输入并返回复杂的对象层次结构.
方法B采用对象层次结构并对其执行某些操作.
我理解如何测试方法A(以及它依次调用的各种其他方法).我对如何最好地测试方法B感到困惑.
我可以在我的单元测试中构建一个假对象层次结构作为方法B的输入,但是当我这样做时,感觉就像我的单元测试变得不再是方法B的测试而更多的是测试我是否手动创建了有效对象层次正确.
对我来说,测试方法A,保持输出然后用它来测试方法B似乎更合乎逻辑但我明白每个单元测试只是为了测试一件事.
我(想)我理解嘲弄和伪造的概念,但我不确定这是答案,因为方法B将使用整个对象层次结构而不只是看它的一小部分.
我很好奇为什么抽象方法必须被第一个具体的实现类覆盖,而不是层次结构更改.
我不是建议我想这样做,但我很好奇为什么它必须是第一堂课
考虑这个例子
abstract class Upper
{
abstract void doSomething();
}
class Middle extends Upper
{
void doSomething()
{
// I'm forced to be implemented here
}
}
abstract class Lower extends Middle
{
}
class Bottom extends Lower
{
void doSomething()
{
// I'm valid, but I'm too far down the hierarchy
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个文档
{_id:NumberLong(1),gender:"M",vip:false}.
Run Code Online (Sandbox Code Playgroud)
如何使用查询在 Mongo 中提取单个字段的类型.. 如何使用 typeof 运算符:
我有一个定义层次结构的表:
Create Table [example] (
id Integer Not Null Primary Key,
parentID Integer Null,
largeData1 nVarChar(max) Null,
largeData2 nVarChar(max) Null);
-- largeData3...n also exist
Insert Into [example] (id, parentID, largeData1, largeData2)
Select 1, null, 'blah blah blah', null Union
Select 2, 1, null, null Union
Select 3, 1, 'foo bar foobar', null Union
Select 4, 3, null, 'lorem ipsum' Union
Select 5, 4, null, null;
Run Code Online (Sandbox Code Playgroud)
此数据的层次结构图:
我想编写一个查询,它将返回任何给定[id]值的单行.该行应包含该行的[id]和[parentID]信息.它还应包含[largeData1 ... n]字段.但是,如果largeData字段为null,则它应该遍历层次结构,直到遇到该字段的非null值.简而言之,它应该像coalesce函数一样运行,除了行的层次结构而不是一组列.
例:
其中[id] = 1:
id: 1
parentID: null
largeData1: blah blah …
Run Code Online (Sandbox Code Playgroud) 我有一个NSDictionary
包含许多不同类型的对象实例(NSArrays
,NSDictionaries
,NSStrings
,NSNumbers
,等...).许多NSDictionaries
并NSStrings
拥有自己的嵌套NSDictionaries
和NSArrays
.
我在整个层次循环,从顶部到底部,以及如何转换的所有实例NSDictionaries
,并NSArrays
以NSMutableDictionaries
和NSMutableArrays
分别?
是否有任何简单的"递归制作可变副本"功能我不知道?如果没有,我是否只需要反复循环和键入检查?我可以随时更换,还是重建整个层次结构?
我正在尝试跟踪IO资源泄漏,其中连接已打开但未必关闭:
try{
...
urlConnection.connect();
...
connectionResult.setResultInputStream(urlConnection.getInputStream());
return connectionResult;
} catch (IOException e) {
throw new ValidationException(e, new LocationData(submissionURL.toExternalForm(), -1, -1));
}
Run Code Online (Sandbox Code Playgroud)
有没有办法可以找出ValidationException
通过调用层次结构捕获的位置?手动步骤如下:
catch Exception
等)在这里,我想渲染引擎的父应用程序的布局,即在层次结构引擎的父application.html.erb应该更高.但是由于引擎也有application.html.erb它只渲染它而不渲染引擎的父application.html.erb.
如何将我的父application.html.erb与我的引擎application.html.erb一起呈现
谢谢
我刚刚学习oop并且正在努力解决继承和多态之间的差异.
如果我理解正确,继承定义了类型层次结构和类之间的关系.子类从父类继承行为,并且可以提供父级上任何公共接口的专门行为.
多态性是这些子类可以提供自己的行为,同时仍然遵循父接口.
这是不是一回事吗?
我在iOS中使用故事板.第一个屏幕是登录屏幕.当用户注销或退出时,他可能位于深层次结构的屏幕上.
例如:login view controller => modal view controller => tab bar controller => nav controller => view controller => view controller.我想从最顶层的视图控制器一直回到底部控制器.
编辑:这是视图层次结构图:
谢谢!
我有一个存储代理层次结构的表:
create table agent (
agent_id int not null,
agent_name varchar(255),
agent_parent_id,
constraint pk_agent primary key (agent_id));
alter table agent
add constraint fk_agent_agent foreign key (agent_parent_id) references (agent_id);
Run Code Online (Sandbox Code Playgroud)
我把它建模为:
class Agent {
String agentName
Agent agentParent
static mapping = {
id column: 'agent_id'
id generator: 'sequence', params: [sequence: 'agent_id_seq']
}
}
Run Code Online (Sandbox Code Playgroud)
每个代理可能有许多属性:
create table agent_property (
agent_property_id int not null,
agent_property_name varchar(255),
agent_id int,
constraint pk_agent_property primary key (agent_property_id));
alter table agent_property (
add constraint fk_agent_property_agent foreign key (agent_id) references …
Run Code Online (Sandbox Code Playgroud) ios ×2
java ×2
oop ×2
coalesce ×1
eclipse ×1
exception ×1
grails ×1
grails-orm ×1
hierarchy ×1
iphone ×1
mongodb ×1
mongodb-java ×1
nsarray ×1
nsdictionary ×1
objective-c ×1
recursion ×1
ruby ×1
uistoryboard ×1
unit-testing ×1