Context
When writing test, I always use the Given-When-Then
formula and in some cases I would like to make sure that the assertions during the Then
are the consequence of the When
and not that something that was done before the When
and my test is given false positives.
Question
1) Is a bad practice to make some assertions during the Given
to make sure that the environment is set as expected and the assertions during Then
are direct consequence of the When
actions?
Example in pseudocode:
//Given
clearAllElementsInDatabase
assertDatabaseIsEmpty
//When
insertElementInDatabase
//Then
assertDatabaseContainsInsertedElement
2) If is a bad practice, what other solution should be done to make sure that the assertions during Then
are the consequence of the actions done in When
?
Aucun commentaire:
Enregistrer un commentaire