0

I am writing Unit/Component test using In Memory DB. When I write Unit/Component test, I came across with the following question.

I have the following two BL methods.

  1. ToCreate
  2. ToGet

So when I write Unit/Component test, I need to create some sample data for the unit test.

When I write a Unit/Component test for "ToGet" method, can I use ToCreate (BL method) to create sample data or When I write a Unit/Component test for "ToCreate", Can I use "ToGet" method to check the created data? Is that a correct choice?

Jeeva Jsb
  • 101

1 Answers1

1

Perhaps you should consider writing unit tests from a more coarse grained perspective. Try focusing on usage scenarios and features instead of methods of a class.

For instance, you could have a unit test like

[Fact]
public void PersistedObjectCanBeFetched() {
    ... 
}

instead of two tests like

[Fact]
public void CreateSucceeds() {
    ...
}

[Fact]
public void GetSucceeds() {
    ...
}

A single test might call many methods of the unit under test if that's what the scenario requires. What's important is that features of the tested unit work as a whole.

COME FROM
  • 2,684
  • 17
  • 15