Jump to content
  • Advertisement
Sign in to follow this  
Quat

Unit Test View Model Button Press

This topic is 656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am new to unit testing and have the following question.  I have a WPF app that uses MVVM and I am working on unit testing the view model.  My UI has a button which the view model abstracts as a command, and when it is pressed it sets the state of a few properties and posts an event.  My question is whether I should make one unit test that asserts everything I expect to happen from the button press (psuedocode):

 

// Arrange
 
btnCommand.Execute(null); // basically button press handler
 
Assert(StateA == X)
Assert(StateB == Y)
Assert(StateC == Z)
Verify event was posted

 

or should I separate these out into 4 separate tests with only one assert per test?

 

 

Share this post


Link to post
Share on other sites
Advertisement

Let's say you have a UI that controls a traffic intersection.

 

One button changes the lights so that traffic flows north-south, the other east-west.

 

If you press the button for north-south, the following must happen.

- The north-south red lights are switched off

- The north-south green lights are switched on

- The east-west green lights are switched off

- The east-west red lights are switched on

 

What would happen if any of these actions/states did not happen? The system would be in an invalid state.

 

So to test one "unit" of functionality, your test should assert that everything under its control is in the correct state.

 

 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!