What are the best methods for unit testing a library / structure?

Context

I am struggling to write a set of unit tests for the library / structure that I am developing. For context, please think of my library as an object level over a hierarchical set of related objects.

Question

Basically, I try to adhere to the principles and best practices regarding unit testing, as shown in a few posts here , but they seem contradictory with respect to specific unit testing of a library or framework.

For example, a basic test deals with “artifact creation”. And one more with the "removal of the artifact." But, since the unit test should be autonomous and restore the state of the world after its completion, both of these tests seem somewhat related in any case: when testing the creation of an artifact, we need to clear the state at the end of the test by actually deleting it. This means that artifact deletion itself is implicitly checked. And the same considerations apply to testing removal of artifacts: in order to set up the world so that removal of artifacts can be tested, we first need to create a new artifact.

The situation is aggravated when we need a unit test to create and delete related sub-artifacts, for which we will need to configure the world accordingly.

, , unit test (.. ), , . :

[create artifact] → [create sub artifact] → [ ] → [ ]

/ , . , " ".

, ?

unit test ?

+3
6

, , , .

, , API . , , , .

, :

  • ( , ).
  • API

, , , . 10% , .

: , , unit test, Junit, . . , , , - , .

, , , .

+1

" " , , ?

, , -, . , .

, , " ", , . , , , ..

, , .

, ... . , , .

, " ". .

+2

. , ( ) .

, ( ). teardown ( ), .

, (, ).

+1

, . Java TestSuites JUnit API. TestSuite TestSuite .

0

, :

  • , .
  • , .
  • . db: unit. "" ( ).

, : . , , ; , db: unit . .

, . ( ) , . , , 4 , , , . . ( 100 1000 ). , fixturs ( ) .

Kent Beck Test Driven Development: .

0
0

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


All Articles