没有得到值xctest

没有得到值xctest

问题描述:

我已经声明了一个方法叫做按钮状态-(int)buttonstate;没有得到值xctest

xctest.m当我instansiate我的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

这两种方法都在同样的看法?并且你想在其他控制器中传递状态值? – 2015-04-06 09:16:41

+0

如果UITextField包含文本,那么uiButton将启用,值将为1,我需要在xctest.m文件中的j值我得到的值为0如果我运行测试之前视图分配的值是1后,当我请参阅(int kn)它是0 – 2015-04-06 09:21:06

+0

必须在调用buttonstate以在运行测试用例时看到值1之前,在testwithoutData中启用serachButton。 – 2015-04-06 10:11:33

这是我曾尝试 -

在ViewController.h

@interface ViewController : UIViewController{ 
    @public int index; 
} 

在ViewController.m

​​ 种

在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); 
} 

测试结果 - enter image description here

+0

当我打电话画圆的方法之前登录索引值,我得到的指数值0 – 2015-04-06 10:19:18

+0

请详细说明,以及如何获得10 – 2015-04-06 10:28:49

+0

为了显示我在ViewControllerTests画圆法设置索引值,我称这种方法只是记录指数前值在testExample。我想没有调用画圆,但那个时候我得到的索引值0。当我调试,我发现的ViewController该实例得到改变和指标值的变化,从10到0。我呼吁在视图控制器viewDidLoad中画圆的方法。因此,我建议您先调用searchbutton启用方法,然后尝试检查要打印的值。希望这可以帮助。检查附加的测试结果截图。 – 2015-04-06 10:39:31