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

Thus, the Agile standard philosophy would recommend making your domain classes simple POCOs that are stored using a separate proxy level through data access objects (e.g. NHibernate). He also recommends getting the maximum unit test coverage possible.

Does it make sense to write tests for these simple POCO objects? Let's say I have a class that 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?

+3
source share
5 answers

Typically, such a value object should not have its own tests. You will get coverage from classes that use it to do something.

. ? .

+12

, , , , . , , , , , , null . , , , , , . , , , .

, ContainerId ? ? , .. , , null , , ?

, . , , , Factory. Factory, , , .

, , , , .

+6

, , , , - (.. ).

, . , Container() . , , .

+3

unit test "" .

, , - ; , , .

, .

Contents. .

+1

I would say that this is not even an object, but an object is determined by its behavior, and this class does not. This is a clean data container. This is also normal, and they usually do not need any tests, but be careful not to get the Anemic Domain Model . Using Test Driven Development will “make” you first think about the behavior of your classes and can be a good exercise.

0
source

Source: https://habr.com/ru/post/1699617/


All Articles