Re: best way to reuse a set of tests
"Charlie Poole" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <000301c8b99f$e78375b0$660d0c0a@ferrari> |
Hi Eric, I noted this question tacked on the bottom of your later question and saw that nobody had replied. Basically, I"m not sure I understand your problem. The code looks good to me and should be reusable by setting a different form. What happens when you do this? Charlie PS: Expect delayed responses from me over the next month, while I'm travelling. _____ From: [email protected] [mailto:[email protected]] On Behalf Of Eric Sent: Saturday, April 19, 2008 9:27 PM To: [email protected] Subject: [Nunit-users] best way to reuse a set of tests I want to reuse a test that verifies a windows form closes properly, and the only thing that varies would be a given form, which also must be an IClosingWindowView, highlighted below. Sorry to ask what sounds like a basic question, but I'm basically stumped on this right now. Code is below. TIA, Eric using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using System.Windows.Forms; namespace ef.GUI { [TestFixture] public class ClosingWindowTest { private IClosingWindowView _view; private Form _form; private ClosingWindowPresenter _presenter; private MockYesNoMessageAsker _mockYesNoAsker; [SetUp] public void SetUp() { _setupYesNoMessageAsker(); _setUpIClosingWindowView(); _setupPresenter(); } private void _setupPresenter() { _presenter = new ClosingWindowPresenter(_view, _mockYesNoAsker); Assert.That(_form.IsDisposed, Is.False); Assert.That(_mockYesNoAsker.WasInvoked, Is.False); } private void _setupYesNoMessageAsker() { _mockYesNoAsker = new MockYesNoMessageAsker(); } /// <summary> /// Set up view; we want the Form just to check it has been closed (IsDisposed), /// but the Presenter never has any knowledge of anything to do with forms, just the IView. /// </summary> private void _setUpIClosingWindowView() { _form = new frmClosingWindow(); <------- the thing that would vary across tests _view = _form as IClosingWindowView; } [Test] public void CloseTheScreen_WhenTheScreenIsNotDirty() { // setup unique to this test _view.IsDirty = false; // trigger state changing behavior _presenter.Close(); // validate expectation(s) // - the msg box is not invoked Assert.That(_mockYesNoAsker.WasInvoked, Is.False); // - the window closes Assert.That(_form.IsDisposed, Is.True); } [Test] public void CloseTheScreen_WhenTheScreenIsDirty_UserContinuesCancelAndDiscardsChanges() { // setup unique to this test _view.IsDirty = true; _mockYesNoAsker.DidTheMockUserClickOk = true; // trigger state changing behavior _presenter.Close(); // validate expectation(s) // - the msg box IS invoked Assert.That(_mockYesNoAsker.WasInvoked, Is.True); // - the window closes Assert.That(_form.IsDisposed, Is.True); } [Test] public void CloseTheScreen_WhenTheScreenIsDirty_UserCancelsClosing() { // setup unique to this test _view.IsDirty = true; _mockYesNoAsker.DidTheMockUserClickOk = false; // trigger state changing behavior _presenter.Close(); // validate expectation(s) // - the msg box IS invoked Assert.That(_mockYesNoAsker.WasInvoked, Is.True); // - the window stays open Assert.That(_form.IsDisposed, Is.False); } } } ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Nunit-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nunit-users