Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What unit tests should be written for simple POCO domain objects?

So standard Agile philosophy would recommend making your domain classes simple POCOs which are Persisted using a separate proxy layer via data access objects (like NHibernate does it). It also recommends getting as high unit test coverage as possible.

Does it make any sense to write tests for these simple POCO objects? Say I have a class which looks like this:

public class Container {
 public int ContainerId { get; set;}
 public string Name { get; set;}
 public IList<Item> Contents { get; set;}
}

What useful unit tests can I write for this?

like image 655
George Mauer Avatar asked Nov 15 '08 21:11

George Mauer


People also ask

What is the best way to write a simple unit test?

A typical unit test contains 3 phases: First, it initializes a small piece of an application it wants to test (also known as the system under test, or SUT), then it applies some stimulus to the system under test (usually by calling a method on it), and finally, it observes the resulting behavior.

How do you test for DDD?

To diagnose DDD, you may need to have some imaging tests. You may have an x-ray, which can help your surgeon "see" the bones in your spine. X-rays are effective at showing narrowed spinal channels (spinal stenosis), fractures, bone spurs (osteophytes), or osteoarthritis.

Should I write unit tests for models?

No. Such test provide little to no value as you will be creating model instances in other tests, for components that work with/use said models. As such, you don't need dedicated model tests because they will be tested indirectly many, many times.


Video Answer


1 Answers

Typically a value object like that doesn't need to have its own tests. You'll get coverage from the classes that use it to actually do something.

The unit tests are designed to test behavior. No behavior? No need for a test.

like image 169
Jeffrey Fredrick Avatar answered Sep 24 '22 14:09

Jeffrey Fredrick