Domanda

Ho una manciata di test SpecFlow che assomigliano a questo:

Scenario: Person is new and needs an email
Given a person
And the person does not exist in the repository
When I run the new user batch job
Then the person should be sent an email

Scenario: Person is not new and needs an email
Given a person
And the person does exist in the repository
When I run the new user batch job
Then the person should not be sent an email

Tranne invece di soli 2 scenari, ho 10 scenari molto simili, tutti con il tipo di passaggi, quindi voglio usare un "profilo di scenario". Sfortunatamente, mi sto divertendo davvero a trovare un modo leggibile per riscrivere i miei passi.

Attualmente, ho escogitato questo ma sembra goffo:

Scenario: Email batch job is run
Given a person
And the person '<personDoes/NotExist>' exist in the repository
When I run the new user batch job
Then the person '<personShould/NotGetEmail>' be sent an email

Examples:
| !notes   | personDoes/NotExist | personShould/NotGetEmail |
| Exists   | does not            | should                   |
| No Exist | does                | should not               |

L'ho anche considerato, e mentre è più pulito non trasmette anche significato

Scenario: Email batch job is run
Given a person
And the person does exist in the repository (is '<personExist>')
When I run the new user batch job
Then the person should be sent an email (is '<sendEmail>')

Examples:
| !notes   | personExist | sendEmail |
| Exists   | false       | true      |
| No Exist | does        | false     |

Qualcuno ha un modo migliore per parametrizzare concetti come "fa", "non", "dovrebbe", "non dovrebbe", "ha", "non ha"? A questo punto, sto pensando di lasciare tutto come uno scenario diverso perché è più leggibile.

È stato utile?

Soluzione

Ecco cosa ho fatto in passato:

Given these people exist in the external system
| Id | First Name | Last Name | Email |
| 1  | John       | Galt      | x     |
| 2  | Howard     | Roark     | y     |
And the following people exist in the account repository
| Id | External Id | First Name | Last Name |
| 45 | 1           | John       | Galt      |
When I run the new user batch job
Then the following people should exist in the account repository
| External Id | First Name | Last Name | Email |
| 1           | John       | Galt      | x     |
| 2           | Howard     | Roark     | y     |
And the following accounts should have been sent an email
| External Id | Email |
| 2           | y     |

È possibile utilizzare la tabella.CreateSet () e la tabella.CreateSet () Metodi helper in SpecFlow per trasformare rapidamente le tabelle in dati per il repository di sistemi esterni falso e la tabella dell'account nel database.

Quindi è possibile utilizzare table.caretoset (AccounTrepository.getAccounts () per confrontare la tabella nella clausola "quindi" con i record nel database.

La cosa pulita è che tutti i passaggi che hai scritto sono riutilizzabili per più situazioni. Tutto quello che fai è cambiare i dati nelle tabelle e SpecFlow scrive i test per te.

Spero possa aiutare!

Altri suggerimenti

Forse dovresti dividerli in due scenari

Scenario Outline: User exists in the repository
Given a person
| Field | Value   |
| First | <first> |
| Last  | <last>  |
And the person exists in the repository
When the user attempts to register
Then the person should be sent an email

Examples:
| first   | last   |
| Bob     | Smith  |
| Sarah   | Jane   |

E poi un altro scenario per il contrario. Questo mantiene lo scenario che significa molto chiaro. Se i tuoi passaggi comuni sono formulati generosamente, puoi riutilizzarli. Cerco anche di venire dall'approccio dell'utente

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top