Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing business logic inside button event #5

Closed
shandysawyer opened this issue Jan 17, 2022 · 1 comment
Closed

Testing business logic inside button event #5

shandysawyer opened this issue Jan 17, 2022 · 1 comment

Comments

@shandysawyer
Copy link

Just a preface, I am still learning how to unit test and still learning the MVP pattern and its different flavors, so apologies in advanced.

I noticed you have a unit test around saving a customer, which is ultimately called by the button event (editButton_Click). This becomes awkward because you can't test all the code in the button click, just the save customer. I realize this is a basic example, but lets say I want test that edit logic.

I noticed other implementations may wrap an event around the button click in the interface to expose the event:
ICustomerView

event EventHandler EditButtonClick;

CustomerForm

public event EventHandler EditButtonClick
{
    add { this.editButton.Click += value; }
    remove { this.editButton.Click -= value; }
}

CustomerPresenter

_view.EditButtonClick += (s, e) => { /*logic here, need references to edit mode and textbox.readonly*/  }

However exposing the editmode property and the readonly property of the textboxes feels messy...

So without going to far down this rabbit hole, what do you think is the best way to go about refactoring so you could unit test this?

@mrts
Copy link
Owner

mrts commented Jan 17, 2022

This becomes awkward because you can't test all the code in the button click, just the save customer.

That's exactly the point of MVP - all the event handler inside the view should do is to invoke the corresponding presenter method. The view should be as "dumb" as possible, there should be no other logic in the event handler. If this is so, testing the presenter method is enough and testing the view code adds no value, only complicates things.

@mrts mrts closed this as completed Jan 17, 2022
@mrts mrts pinned this issue Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants