F# 将AfterScenario与TickSpec一起使用

F# 将AfterScenario与TickSpec一起使用,f#,gherkin,F#,Gherkin,我有这样一个功能文件: Feature: Viewing revenue Background: Given invoices | Date | Amount | | 1/1/2010 | 200 | | 1/1/2011 | 300 | Scenario: Total revenue Then the total revenue is | Label | Revenue | | | $500 | Scenario: Total revenue by

我有这样一个功能文件:

Feature: Viewing revenue

Background:
Given invoices
| Date     | Amount |
| 1/1/2010 | 200    |
| 1/1/2011 | 300    |

Scenario: Total revenue
Then the total revenue is
| Label | Revenue |
|       | $500    |

Scenario: Total revenue by year
When I choose to view it by "Year"
Then the total revenue is
| Label | Revenue |
| 2010  | $200    |
| 2011  | $300    |
我想在每个场景执行后运行一些清理代码。我有一个用AfterScenario属性修饰的函数,如图所示:

let [<AfterScenario>] ``Drop Invoices`` () =
  Invoices.removeAll
let[]`Drop Invoices``()=
移动电话

该函数确实会被调用,但只有一次,而且只有在我通过NUnit的gui运行程序重新加载项目时才会被调用。在不重新加载项目的情况下,后续的测试运行不会调用该函数。

调用
发票。removeAll
似乎缺少一个参数,您可能需要添加

期望属性化方法返回单位,因此您可能需要通过管道将结果忽略。您可以将鼠标悬停在
Drop Invoices
函数上,检查该函数的类型,如果不尝试此操作,则应显示unit->unit:

let [<AfterScenario>] ``Drop Invoices`` () =
  Invoices.removeAll () |> ignore
let[在2012年11月发行的TickSpec之前,如果在场景中执行步骤时引发异常,则不会调用AfterStep和AfterScenario函数。这在最新的源代码中已修复,程序集可通过或获得


如果您有多个标记为AfterScenario的函数,并且其中任何一个都会引发异常,那么后续的AfterScenario方法将不会被调用。理想情况下,BeforeSceanrio和AfterScenario函数不应该抛出。

感谢您的详细响应。将单元传递给
removeAll
成功了。我还不清楚这一点,因为removeAll被定义为:
let removeAll=Invoices.removeAll()
(其中Invoices指的是MongoDB集合)。我必须添加一个单位参数:
let removeAll()=…
,以完成这个难题。