Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Writing a test to ensure that a system tracks a person's age is not a unit test, IMO. That's an integration test. A unit test would test the generic unit of execution (aka "procedure") that, say, computes an age value from, say, a base date and an offset in whatever units (days, weeks, etc). My point is that bit of code shouldn't have any weird out-going dependencies on the rest of the system. It JUST calculates an age from a couple of input values, and in that case a unit test can confirm the correct behavior, which is probably to throw an exception if the offset produces a negative age. Commented Apr 12, 2014 at 23:30
  • I was not referring to any calculation. If a model stores a piece of data, it can validate the data belongs to the correct domain. In this case, the domain is the set of nonnegative integers. Calculations should occur in the controller (in MVC), and in this example an age calculation would be a separate test. Commented Apr 14, 2014 at 14:30