簡體   English   中英

如何驗證獼猴桃bdd測試用例中的didReceiveMemoryWarning功能?

[英]How to verify didReceiveMemoryWarning function in kiwi bdd test cases?

我面臨的問題是要驗證是否使用獼猴桃測試用例接收了內存警告功能。 如何驗證功能?

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

有人知道獼猴桃測試用例嗎?

您可以直接直接調用該方法:

it(@"Should cleanup when receiving a memory warning", ^{
    [controller didReceiveMemoryWarning];
    // assert here that the data that you expected was released
});

通過這種方法,你需要通過你希望是控制器的性能走路nil-ed在內存警告的可能性。

或者,您可以檢查單元測試應用程序的內存使用情況,並在模擬內存警告后查看內存是否減少了。 這不如第一種方法准確,但可以給您一些提示。 而且,您還需要確保控制器將在屏幕上呈現,或者至少使其認為已呈現,然后開始構建視圖/表格視圖單元等。

it(@"Should cleanup when receiving a memory warning", ^{
    vm_size_t memoryBeforeMemWarning;
    vm_size_t memoryAfterMemWarning;
    MyController *controller = nil;

    @autoreleasepool {
        controller = ...;
        // call controller.view, or other methods that create the view
        // also call any other methods that trigger subview creation

        memoryBeforeMemWarning = getMemUsage();
        //simulate the memory warning
        [controller didReceiveMemoryWarning];
    }
    memoryAfterMemWarning = getMemUsage();

    // reference the variable here to make sure ARC doesn't
    // release it when it detects its last reference
    controller = nil;

    // now assert upon the difference between the two reported memory usages
});

您需要使用一個autorelease pool具有了與創建對象的控制autorelease ,因為這些物體會當你得到釋放autorelease pool范圍結束時的主,而不是autorelease pool被耗盡。
注意。 我沒有添加getMemUsage()的實現,您可以在此處了解如何實現它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM