State vs. Interaction testing in presenters

1 view
Skip to first unread message

Bil Simser

unread,
May 28, 2008, 5:59:18 PM5/28/08
to xeva
In the BankTeller app all the tests seem to be interaction testing or
some kind of state based testing (but the state is all setup in the
test so IMHO the test seems somewhat bogus). I guess you can always
use SetupResult.For(view.Property) but is this a good way to test
state in the views?

Bil Simser

unread,
May 29, 2008, 7:47:29 AM5/29/08
to xeva
I guess to followup I'm trying to see the difference between something
like this:

[Test]
public void All_fields_should_be_clear_on_startup()
{
SetupResult.For(_view.Username).Return(string.Empty);
SetupResult.For(_view.Password).Return(string.Empty);

using (Record)
{
}
using (Playback)
{
_presenter.Start();
}
}

And this which also passes and to me is the same:

[Test]
public void All_fields_should_be_clear_on_startup()
{
_presenter.Start();
Assert.AreEqual(string.Empty, _view.Username);
Assert.AreEqual(string.Empty, _view.Password);
}

Is there a difference given how the presenter/view/callbacks are wired
together?

David Laribee

unread,
May 29, 2008, 9:18:21 AM5/29/08
to xe...@googlegroups.com
Well your first test is kind of meaningless. Of course it will always pass; there's no real assert in there of any kind.

The second test is A-OK. That would be more of an integration test (e.g. don't use the AMC). You could consider doing an interaction test for the same thing like so:

using (Record)
{
    Get<ISomeView>().ClearData();
}

using (Playback)
{
    presenter.Start();  
}

We tend to manage our state in the presenter. The view will get an initial bindable DTO and sometimes provide a DTO that's meant to go to a service. So the state we maintain in the presenter tends to be in the Request used to start it (if any). This'll tend to be claim check stuff like "the ID of the entity I'm viewing."

As to the specs in the BankTeller example the SetupResults are just to get the specs working (i.e. true "stubs"). It's very possible (likely) that these samples are underspecified, so you would want a specification detailing the behavior you mention (cleared fields). I'd more than likely do it as a presenter-to-view call through the view interface and interaction test it (as per above).

Hope this helps...
--


/ Dave

http://thebeelog.com
Reply all
Reply to author
Forward
0 new messages