我真的很难理解单元测试.我确实理解TDD的重要性,但我读到的所有单元测试的例子似乎都非常简单和微不足道.例如,测试以确保设置属性或将内存分配给数组.为什么?如果我编码..alloc] init],我真的需要确保它有效吗?
我是开发新手,所以我肯定我在这里缺少一些东西,特别是围绕TDD的所有热潮.
我认为我的主要问题是我找不到任何实际的例子.这是一种setReminderId 似乎很适合测试的方法.什么是有用的单元测试看起来确保这是有效的?(使用OCUnit)
- (NSNumber *)setReminderId: (NSDictionary *)reminderData
{
NSNumber *currentReminderId = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentReminderId"];
if (currentReminderId) {
// Increment the last reminderId
currentReminderId = @(currentReminderId.intValue + 1);
}
else {
// Set to 0 if it doesn't already exist
currentReminderId = @0;
}
// Update currentReminderId to model
[[NSUserDefaults standardUserDefaults] setObject:currentReminderId forKey:@"currentReminderId"];
return currentReminderId;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用https://github.com/mikeal/request.我的代码出了什么问题?错误消息在代码下.在我的程序中,我使用的是真正的App和Rest ID
var request = require('request');
request.post( {
url: 'https://api.parse.com/1/classes/GameScore',
headers: {
"X-Parse-Application-Id": "11111",
"X-Parse-REST-API-Key": "222222",
"Content-Type": "application/json"
},
body: {
"score": 1337, "playerName": "Sean Plott", "cheatMode": false
}
},
function (error, response, body) {
if(response.statusCode == 201){
console.log('Status Update');
} else {
console.log('error: '+ response.statusCode);
console.log(body);
}
}
);
Run Code Online (Sandbox Code Playgroud)
错误信息:
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Argument error, options.body.
at Request.init (/mnt/ws/users/$mn/mnort9/165767/node_modules/request/main.js:264:13)
at new Request (/mnt/ws/users/$mn/mnort9/165767/node_modules/request/main.js:102:8)
at request (/mnt/ws/users/$mn/mnort9/165767/node_modules/request/main.js:800:11) …Run Code Online (Sandbox Code Playgroud) 我有一个在后台播放音频的应用程序.我正试图beginBackgroundTaskWithExpirationHandler在当前曲目结束时跳到下一首曲目.
以下是播放状态更改时调用的代码.它永远不会记录"beginBG called",即使同一方法中的其他代码在后台成功实现.
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[self ffwButtonPressed:ffwButton];
NSLog(@"beginBG called");
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
Run Code Online (Sandbox Code Playgroud)
ffwButtonPressed调用一些不同的方法来改变轨道.什么时候完成......
UIApplication *app = [UIApplication sharedApplication];
if (bgTask != UIBackgroundTaskInvalid) {
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
NSLog(@"end bgTask");
Run Code Online (Sandbox Code Playgroud)
编辑:声明
UIBackgroundTaskIdentifier bgTask;
Run Code Online (Sandbox Code Playgroud)
编辑:在ViewDidLoad中
bgTask = 0;
Run Code Online (Sandbox Code Playgroud) 我对 OAuth 和 Google 感到很困惑。我花了很长时间才获得 refresh_token 以创建新的 access_token。然后找出refresh_token也过期了??这有什么意义!!!?
我需要做的就是保留一个有效的 access_token 以与legato一起使用。
这是我手动输入终端以检索 OAUTH 代码的内容:
client = OAuth2::Client.new('GA_CLIENT_ID', 'GA_SECRET_KEY', {
:authorize_url => 'https://accounts.google.com/o/oauth2/auth',
:token_url => 'https://accounts.google.com/o/oauth2/token'
})
client.auth_code.authorize_url({
:scope => 'https://www.googleapis.com/auth/analytics.readonly',
:redirect_uri => 'http://localhost',
:access_type => 'offline',
:approval_prompt=> 'force'
})
Run Code Online (Sandbox Code Playgroud)
然后我在浏览器中手动输入输出的 url。我将返回的 OAUTH 代码导出为一个 env 变量并获取访问令牌:
access_token = client.auth_code.get_token(ENV['GA_OAUTH_CODE'], :redirect_uri => 'http://localhost')
Run Code Online (Sandbox Code Playgroud)
然后我可以访问 access_token 和 refresh_token:
begin
api_client_obj = OAuth2::Client.new(ENV['GA_CLIENT_ID'], ENV['GA_SECRET_KEY'], {:site => 'https://www.googleapis.com'})
api_access_token_obj = OAuth2::AccessToken.new(api_client_obj, ENV['GA_OAUTH_ACCESS_TOKEN'])
self.user = Legato::User.new(api_access_token_obj)
self.user.web_properties.first # this tests the access code and …Run Code Online (Sandbox Code Playgroud) 我理解如何实现单元测试,我只是在努力弄清楚何时使用它们.
假设我有一个基本的提醒应用程序.用户可以添加/编辑/删除提醒并在桌面视图中查看它们.我想为应用程序的哪些部分设置单元测试?
我似乎无法掌握如何使用NodeJ维护异步控制流.在我看来,所有嵌套都使得代码很难阅读.我是新手,所以我可能错过了大局.
简单编码这样的东西有什么问题......
function first() {
var object = {
aProperty: 'stuff',
anArray: ['html', 'html'];
};
second(object);
}
function second(object) {
for (var i = 0; i < object.anArray.length; i++) {
third(object.anArray[i]);
};
}
function third(html) {
// Parse html
}
first();
Run Code Online (Sandbox Code Playgroud) 我有一个UITapGestureRecognizer链接到一个IBAction.我只是想确认IBAction方法调用.对于UITapGestureRecognizer,在故事板中,我在视图中有一个参考插座集合到gestureRecognizers,并且发送tapGesture:了与我的ViewController相关联的动作.
.h代码:
- (IBAction)tapGesture:(UITapGestureRecognizer *)sender;
Run Code Online (Sandbox Code Playgroud)
.m代码:
- (IBAction)tapGesture:(UITapGestureRecognizer *)sender {
NSLog(@"Tapped");
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?为什么tapGesture:不解雇?

我有4个float: left像这样的div容器......

我想在div悬停时显示边框.但是,当我将鼠标悬停在第一个或第二个div上时,它将底部div推向左侧......

我尝试在div中添加margin和padding,但似乎没有任何效果.
.div
{
width: 33%;
}
.div:hover
{
boder: solid 1px #EEE;
}
Run Code Online (Sandbox Code Playgroud) 我有多个集合视图需要使用相同的原型单元格.现在,我在故事板中复制每个集合视图中的原型单元格(如下所示).这不是很干,在对单元格进行故事板更改时会变得很痛苦.
是否可以在故事板中的一个位置定义单元格?
或者我尝试只使用1个集合视图,但我无法获得单元格堆叠和垂直滚动的3列布局,因此我移动到3个集合视图.
objective-c storyboard ios uicollectionview uicollectionviewcell
array =
[ {
:keyword => "A",
:total_value => "10"
},
{
:keyword => "B",
:total_value => "5"
},
{
:keyword => "C",
:total_value => "15"
},
{
:keyword => "B",
:total_value => "6"
},
{
:keyword => "A",
:total_value => "50"
},
{
:keyword => "D",
:total_value => "40"
},
{
:keyword => "A",
:total_value => "30"
}]
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用相同的:keyword值来合并哈希值.通过合并,我的意思是结合:total_value.例如,合并后......
new_array =
[ {
:keyword => "A",
:total_value => "90"
},
{
:keyword => "B",
:total_value …Run Code Online (Sandbox Code Playgroud) 如果在已提交的应用程序的未来版本中更改了软件包显示名称,是否会在用户设备上下载为完全不同的应用程序,或者显示名称是否只是更改?
ios ×6
objective-c ×4
iphone ×3
node.js ×2
ruby ×2
storyboard ×2
unit-testing ×2
arrays ×1
asynchronous ×1
css ×1
css-float ×1
gmail-imap ×1
httprequest ×1
info.plist ×1
oauth ×1
oauth-2.0 ×1
ocunit ×1
tdd ×1
xcode ×1