Device Testing Model

I am looking for a solution / template for the next block testing.

Happening:

Suppose we have three classes, A, B, C each with one method. The method calls Method B, which calls Method C. So A-> B-> C. Each method accepts one input (input A for method A, input B, input C). The result of calling method A will be a tree structure, such as:

Root (created by method A) - Node B (created by method B) - Node C1 - Node C2 (both created from method C)

For me, unit testing is testing the output from the input of a method separately. So, we will write unit tests for each of the above methods. Since the tests are written in isolation, we will mock Method B when writing unit tests for Method A and mock Method C when writing unit test cases for Method B.

So far so good, we can write output expectations for each method to make sure that the resulting tree structure is respected.

Problem:

Now add another class that will call method B, so we will also have the following chain of calls: D-> B-> C. The resulting root tree will look like this:

  • Root D
    • Node B
      • Node C1
      • Node C2

- , A , :

  • A
    • Node B
      • Node C

, C, Node, . , . D , - Node C1 Node C2.

:

, , D? , .

.

+5
3

( , ), Joe Rainsberger . , , - , , , .

, , " C Node, " C . , C , , C .

, C, C2, .

Rainsberger , , , . .

0

"" , unit test, ( ) (UI down). "" .

, :

  • A Unit Test - - .
  • Unit Test ( ) - () (, ) - , .
  • - Hit A .
  • . , - A, - ( Cukes ) .

, , , , A, .

¹ " ", , a Unit Test

+2

Ideally, your unit test should go all the way to class C. A unit test does not necessarily mean ONE METHOD OF ONE CLASS. It just means that you can run it without any other dependencies, such as libraries or databases, etc. Then you need an integration test.

Your unit test should fully penetrate C, and when the requirement changes to A, then the unit test will break, and the developer for D will know that something is wrong.

+1
source

All Articles