在黃瓜中聲明測試數據的位置


3

我正在努力了解在黃瓜方案中放置測試數據的最佳位置。

我的情況如下:

Scenario: Register member for first time
Given I have navigated to new registration page as a member who has never registered for MOS
When I complete the registration form
Then I am navigated to the registration complete page

我將When步驟的測試數據硬編碼在步驟defs中,因為我認為這是功能文件的不必要噪音。我發布了另一篇文章,關於這是否是最佳選擇,我現在正在考慮創建一個屬性文件來存儲此類數據。

這種情況的問題是,一旦我將這個特定的數據用於該測試,它就不再有效地用於該測試。這是因為成員現在處於已註冊狀態,而不是未註冊狀態,這會驅動不同的UI行為。

我知道這裡最理想的解決方法是我的Given步驟可能是探究源系統並找到一些適用於該測試的測試數據,但源系統是非網絡(無硒),我們限制數據庫訪問,以便排除該規則。

我想知道是否有人遇到過類似的挑戰,以及在這種情況下我們可能有什麼解決方法?

目前,我將有一個電子表格(.properties),它將數據輸入到步驟def中,但是一旦運行了該測試一次,則有人將不得不使用一個有效的成員(未註冊成員)刷新該電子表格數據。凌亂,脆弱,可怕!

1

In my opinion you can use 4 approaches:

  1. Create/append a unique ID for every user you create (with something like String uniqueID = UUID.randomUUID().toString();)
  2. Create/append an index, to be stored in a file, to the used ID (so that you will have users like "User_1", "User_2" and so on)
  3. Create/append a timestamp to the user ID to be used
  4. Go to the developers and ask for a way to programmatically delete the data that you just created. The system MUST be adapted to be testable otherwise we will always have these issues and we will only have local improvements. Quality is a responsibility for everyone in the team.

I'd say you can use one of the first 3 approaches as a temporary solution while the 4th one is waiting to be ready.


0

Your given step should include code that sets up the test state that the rest of the code expects. If this is difficult to orchestrate then it hints at your application having potential deployment and migration issues. You might also find that contract testing (see pact) can help you avoid lengthy and expensive end to end testing by allowing you to compare consumer and provider interfaces in isolation.


0

For data setup, we implemented as delete SQL script execution as 'beforeTest' step to make sure same data is re-usable everytime .

As it is inserted as pre-step on the test suite level so it is always executed and further steps are only executed if pre-condition is met (on data deleted successfully).