How (strategy) in unit test (get / set) properties in BDD style?

I have a (many) class that has properties. Some of them have logic, and some do not. Assuming I want to test these properties, how do I do this?

Recently, I have been interested in the BDD style for creating unit tests.

see here and here .

So, I would do a context setting - basically create a SUT and load everything I need. Then, in each observation (test method), I would check that a particular property contains what it should contain.

Here is my question. If a SUT has 20 properties, then I create 20 observations / tests? Maybe if one of the properties contains more interesting logic, I think.

[Observation]
public void should_load_FirstName()
{
    Assert.Equals<string>("John", SUT.FirstName);
}

[Observation]
public void should_load_LastName()
{
    Assert.Equals<string>("Doe", SUT.LastName);
}

[Observation]
public void should_load_FullName()
{
    Assert.Equals<string>("John Doe", SUT.FullName);
}

But would it be better if aggregated simple in one observation?

[Observation]
public void should_load_properties()
{
    Assert.Equals<string>("John", SUT.FirstName);
    Assert.Equals<string>("Doe", SUT.LastName);
    Assert.Equals<string>("John Doe", SUT.FullName);
}

, ( ). , :

[Observation(PropertyName="FirstName", PropertyValue="John")]
[Observation(PropertyName="LastName", PropertyValue="Doe")]
[Observation(PropertyName="FullName", PropertyValue="John Doe")]
public void should_load_properties()
{
}
+3
2

, , . xUnit Test Patterns , , , , , . , , , BDD, ...

, , , , , , ...

xDD (TDD, BDD, ) , . , , , , , , . , SUT.FirstName "", , , "".

, .

, , , .

, , .

, . .

+4

SubSpec ( [Specification]) - Assert . , , , .

0

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


All Articles