Unit Testing your Team Project

In Sprint 3 you allocated 5 story points per person, separately from any User Story, for Unit Testing. For this Sprint you'll need to integrate unit testing directly into all user stories. You will be expected to unit test code that does have external dependencies.

Requirements

  • For every user story you undertake, think about how it can be unit tested. Do this thinking during sprint planning. Increase story points accordingly to take into account the additional overhead of time involved in writing and running unit tests and the inevitable refactoring and defect correction that occurs. It's best not to think of this as “overhead”; rather, think about this as the new normal. This is what high quality professional development is all about.
  • Since you'll almost certainly have dependencies, install Moq and Ninject and get them set up and working.
  • Refactor your code for each user story that touches the database to use the Repository Pattern with Dependency injection and then mock your use of it in unit tests. You should go through the repository for all db access. Don't go directly through the DbContext class anymore.
  • Refactor your code for each user story that uses any other external dependency to use the Repository Pattern as well. Mocking your use of external API's may not be as easy as it is for database access but do your best. At a minimum, refactor and test edge cases.
  • Refactor your code for each user story that uses Javascript in the client and unit test that too. Yes, you heard that right. And, no, you're not off the hook because everything you're doing is in Javascript! See below.
  • Expectations for testing? This is still early and we can't expect full test coverage. What's important in this Sprint is to get everything set up, use the repository pattern, begin mocking and don't break anything. I will expect reasonable test coverage for every user story. If it isn't there then you won't get full grading points for your user story. Reasonable here is defined to be: testing that gives some confidence that the code under test is correct. Doesn't have to be “utmost” or “complete” confidence, just some.
  • As with our first foray into unit testing, add a comment at the top of each test file that lists the User Story ID that you're working on so we can trace tests to requirements.
  • Remember that the Pro ASP.NET MVC 5 book has lots of examples.
  • Make sure all tests pass. During the sprint review meeting you should be ready to "Run All Tests" and show an all-green board.

Unit Testing Javascript

Yes, you can unit test Javascript. Not easy and not as effectively as you can your C# MVC code, but still possible. So you will need to set up testing and write “unit” tests for user stories involving Javascript functionality. While not technically 100% unit testing, it will still be worthwhile, and it will force you to refactor your JS into the modular, testable format it should be in.

I'll describe in class what I think an appropriate strategy is and what tools to use. For now I'll just list the tool and links that I'll use in class. Before that, let's leave a space for identifying the difficulties involved in testing client side code.

Difficulties

Tools and Links