Caves Travel Diving Graphics Mizar Texts Cuisine Lemkov Contact Map RSS Polski
Trybiks' Dive Texts Rhino Mocks Rhino Mocks's AssertWasNotCalled YAC Software
  Back

List

Charsets

Charts

DBExpress

Delphi

HTML

Intraweb

MSTest

PHP

Programming

R

Rhino Mocks

Software

Testing

UI Testing

VB.NET

VCL

WPF

Rhino Mocks's AssertWasNotCalled
In the previous article on AssertWasCalled I presented the Rhino Mocks method for checking whether a method was called during test execution. Sometimes, though, you'd like to check the exact opposite - that a method was not called.

Let's consider a method that's responsible for checking if a document is currently opened in the application. Then, when the user wants to open the same document again, instead of opening the document, the existing document window is activated. But if that window is already active, a message is displayed instead, notifying the user that the document is already opened.

Next, let's say this functionality is provided via two interfaces: IDocumentService and IMessageBoxService. And that we already created the necessary stubs for these: documentService and messageBoxService. Our tests then can go something like this:
  <TestMethod()>
  Public Sub TestOpenDocumentAlreadyOpenedNotActive()
    ' Arrange: Set the environment up so that the document "A.txt" is already opened, but not active:
    . . .
    ' Act:
    OpenDocument("A.txt")
    ' Assert:
    documentService.AssertWasCalled(Sub(its) its.ActivateDocument("A.txt"))
    messageBoxService.AssertWasNotCalled(Sub(its) its.Warning("Document 'A.txt' is already opened."))
  End Sub
  
  <TestMethod()>
  Public Sub TestOpenDocumentAlreadyOpenedAndActive()
    ' Arrange: Set the environment up so that the document "A.txt" is already opened, and active:
    . . .
    ' Act:
    OpenDocument("A.txt")
    ' Assert:
    documentService.AssertWasNotCalled(Sub(its) its.ActivateDocument("A.txt"))
    messageBoxService.AssertWasCalled(Sub(its) its.Warning("Document 'A.txt' is already opened."))
  End Sub
Quite simple, actually; though with both methods, and especially with AssertWasNotCalled, you often want to check that the method was not called at all, regardless what parameters were passed to the method (note that in the examples above, we're checking that messageBoxService.Warning was/wasn't called with that specific text; it could've been called with text that's slightly different...). But that's a slightly wider topic and will be discussed in a separate article.

HTH

Top

Comments
Alas!
No comments yet...

Top

Add a comment (fields with an asterisk are required)
Name / nick *
Mail (will remain hidden) *
Your website
Comment (no tags) *
Enter the text displayed below *
 

Top

Tags

Rhino Mocks

Testing

VB.NET


Related pages

AssertWasCalled and Methods Called Multiple Times

AssertWas[Not]Called and Object Properties

Visual Studio - moving coded UI tests to a new / different project results in null reference exceptions

PrivateObject and Out/ByRef parameters

PrivateObject, WithEvents, and generics

Accessing private members of base classes

CA1800:DoNoCastUnnecessarily

PrivateObject and WithEvents

The creator of this fault did not specify a Reason.

Accessing private and protected members - PrivateObject and PrivateType

VS - Test Run Error - "COM object that has been separated from its underlying RCW cannot be used"

Saving / restoring window placements in .NET

Get the TreeViewItem for an Item in a WPF TreeView

Output in MSTest Tests (VS 2010)

Automated WPF tests and "Invalid URI: Invalid port specified."

Checking Property Change Notifications

Checking "Dangling" Event Handlers in Delphi Forms

Rhino Mocks's AssertWasCalled in VB.NET

First steps with Rhino Mocks (in VB.NET)

Meaningful identifiers

Public fields vs. properties

VS Pending Tests

Automated GUI Testing

Automated GUI Testing in VMs

Automated Testing of Window Forms

Detecting Memory Leaks with DUnit