2014-10-09 44 views
2

當gmock看到一個方法調用它不希望丟失,寫警告這樣的:模仿對象名稱是在警告

GMOCK WARNING: 
Uninteresting mock function call - returning directly. 
    Function call: Constructor() 
Stack trace: 

這並不是非常有益的,當在單元的每個模擬對象test有一個名爲「Constructor」的方法,因爲找出哪個對象創建了這條消息並且缺少一個EXPECT_CALL並不總是那麼容易。

有沒有辦法告訴gmock也寫這樣的警告類名稱或模擬對象的名稱?

回答

0

這真的很不方便。

看看the source of the uninteresting call function report,似乎不可能修改此行爲。對方法調用的可能反應由a fixed enum給出,所以擴展在這裏看起來不是一個選項。您可以將Google測試事件偵聽器附加到測試套件中,但我認爲達到這些信息的信息同樣有限。在我看來,如果這對我來說真的很重要,我會修改Google Mock源代碼中提到的幾行,並且與方法名一起,我會把對象地址(這是最近的東西和標識符)與MockObject()。例如:

// Writes a message that the call is uninteresting (i.e. neither 
    // explicitly expected nor explicitly unexpected) to the given 
    // ostream. 
    virtual void UntypedDescribeUninterestingCall(
     const void* untyped_args, 
     ::std::ostream* os) const 
      GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { 
    const ArgumentTuple& args = 
     *static_cast<const ArgumentTuple*>(untyped_args); 
    *os << "Uninteresting mock function call - "; 
    DescribeDefaultActionTo(args, os); 
    *os << "  Function call: " << Name(); 
    *os << "Mock object address: " << MockObject(); 
    UniversalPrint(args, os); 
    } 

這並不像看起來那麼瘋狂;谷歌Mock是一個測試庫,而不是生產,所以定製(受控)修改在那裏並不是那麼有害。而實際上Google does recommend use a custom compilation of Google Test for each different project

或者你可以向他們發送補丁,看他們是否喜歡它:)

1

我們已經實現了另一種解決這個問題。我們有我們自己的Eclipse插件,它從選定的頭文件生成模擬對象文件。現在我們改變了插件生成一個模擬的名稱中包含類的名稱,例如:

MOCK_METHOD0(Timer_Constructor, void()); 

這將導致警告

Uninteresting mock function call - returning directly. 
Function call: Timer_Constructor()