Is a test without an assert a test?

Right now I’m reading a, so far, good article on the MVP pattern. The article Model View Presenter at MSDN Mag. The author is taking a TDD approach and the first test he writes looks like this:

[Test]
publicvoid ShouldLoadListOfCustomersOnInitialize()
{
    mockery = new Mockery();
    ICustomerTask  mockCustomerTask = 
        mockery.NewMock<ICustomerTask>();
    IViewCustomerView  mockViewCustomerView = 
        mockery.NewMock<IViewCustomerView>();
    ILookupList  mockCustomerLookupList = 
        mockery.NewMock<ILookupList>();

    ViewCustomerPresenter presenter = 
        new ViewCustomerPresenter(mockViewCustomerView,
          mockCustomerTask);
            
    ILookupCollection mockLookupCollection = 
        mockery.NewMock<ILookupCollection>();            
     
    Expect.Once.On(mockCustomerTask).Method(
        "GetCustomerList").Will(Return.Value(mockLookupCollection));
    Expect.Once.On(mockViewCustomerView).GetProperty(
        "CustomerList").Will(Return.Value(mockCustomerLookupList));
    Expect.Once.On(mockLookupCollection).Method(
        "BindTo").With(mockCustomerLookupList);
                        
    presenter.Initialize();
}

Except for noticing the nice fluent interface of NMock2 the thing that struck me was that there is no Assert! I have never written a test without at least one assert to confirm. I’m not saying that it’s wrong to skip the assert. I haven’t had any time to look at NMock2 but I guess he missed a .Verify() at the end.
UPDATE 2006-07-14: My bad about the article author missing out on the .Verify statement. After reviewing the code a little I found it in the TearDown: mockery.VerifyAllExpectationsHaveBeenMet();.

So that means you’ll get an exception if all methods and properties are not accessed, but you don’t have an assert to confirm that the test is ok. Hmm, I don’t know, but it feels wrong. Any other opinions on this matter? Post a comment!

 

2 thoughts on “Is a test without an assert a test?

  1. I’d say that the assert is implicitly defined in the NMock2 expectations.

    Since VerifyAllExpectationsHaveBeenMet() will be called from TearDown() it will assert that all expectations have been met. Thus asserting that your test passed by not throwing an exception.

    Simply put: I don’t think the concept that a test always needs an assert holds in the presence of mock frameworks.

  2. Yeah, I guess this has to do with the notion of a successful test. Is it something that succedes or something that does not fail…

Comments are closed.