我似乎无法在我的fsunit测试中得到缩进。我一直被告知使用ML风格的“使用let ... in”,但这样做意味着编译器无法读取下一个测试的名称。有什么建议吗?
[<TestFixture>]
module ``reading yaml files`` =
let yamlReader = new yamlReader()
let yamlConfig = yamlReader.read("./testFiles/config.yaml")
[<Test>] ``should parse root property of a yaml file`` ()=
yamlConfig.ContainsKey(new YamlScalar("token1")) |> should equal true
[<Test>] ``should parse nested propery of a yaml file`` ()=
let token1 = yamlConfig.[new YamlScalar("token1")] :?> YamlMapping
let env3 = token1.[new YamlScalar("env3")] :?> YamlScalar
env3.Value |> should equal "value3"
[<Test>] ``should convert yamldocument to digestable format`` ()=
let tokens = yamlReader.toTokens yamlConfig
let firstToken = (Seq.head tokens)
firstToken.name |> should equal "token2"
答案 0 :(得分:4)
您缺少let关键字。 试试这个:
[<TestFixture>]
module ``reading yaml files`` =
let yamlReader = new yamlReader()
let yamlConfig = yamlReader.read("./testFiles/config.yaml")
[<Test>]
let ``should parse root property of a yaml file`` ()=
yamlConfig.ContainsKey(new YamlScalar("token1")) |> should equal true
[<Test>]
let ``should parse nested propery of a yaml file`` ()=
let token1 = yamlConfig.[new YamlScalar("token1")] :?> YamlMapping
let env3 = token1.[new YamlScalar("env3")] :?> YamlScalar
env3.Value |> should equal "value3"
[<Test>]
let ``should convert yamldocument to digestable format`` ()=
let tokens = yamlReader.toTokens yamlConfig
let firstToken = (Seq.head tokens)
firstToken.name |> should equal "token2"
答案 1 :(得分:2)
Gustavo的版本是更好的版本(以及我通常使用的版本),但是如果你不想将[<Test>]
放在一个单独的行上:
[<TestFixture>]
module ``reading yaml files`` =
let yamlReader = new yamlReader()
let yamlConfig = yamlReader.read("./testFiles/config.yaml")
let [<Test>] ``should parse root property of a yaml file`` () =
yamlConfig.ContainsKey(new YamlScalar("token1")) |> should equal true
let [<Test>] ``should parse nested propery of a yaml file`` () =
let token1 = yamlConfig.[new YamlScalar("token1")] :?> YamlMapping
let env3 = token1.[new YamlScalar("env3")] :?> YamlScalar
env3.Value |> should equal "value3"
let [<Test>] ``should convert yamldocument to digestable format`` () =
let tokens = yamlReader.toTokens yamlConfig
let firstToken = (Seq.head tokens)
firstToken.name |> should equal "token2"