我已将一个名为按钮状态的方法声明为-(int)buttonstate;
在xctest.m
中,当我实现我的viewController并分配给一个int值时,我得到了错误的值。
-(int) buttonstate {
if ([searchButton isEnabled]) {
j = 1;
}
else
j = 0;
NSLog(@" j value is %d",j);
return j;
}
并在xctest .m文件中
-(void) testwithoutData {
myapiViewController *apiViw = [[myapiViewController alloc]init];
int kn = [apiViw buttonstate];
NSLog(@"the value is %ld",(long)kn);
}
答案 0 :(得分:0)
这是我试过的 -
在ViewController.h中
@interface ViewController : UIViewController{
@public int index;
}
在ViewController.m中
-(void) drawCircle{
index = 10;
NSLog(@"the value is %ld",(long)index);
}
在ViewControllerTests.m
中@interface ViewControllerTests : XCTestCase
@property (nonatomic,strong) ViewController *vcToTest;
@end
@implementation ViewControllerTests
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
self.vcToTest = [[ViewController alloc] init];
}
- (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
[self.vcToTest drawCircle];
NSLog(@"Test is fine. Value %d",self.vcToTest->index);
}
测试结果 -