In F# how do you pass a collection to xUnit's InlineData attribute

前端 未结 6 783
故里飘歌
故里飘歌 2021-01-02 00:28

I would like to be about to use a list, array, and/or seq as a parameter to xUnit\'s InlineData.

In C# I can do this:

using Xunit; //2.1.0

namespace C         


        
6条回答
  •  半阙折子戏
    2021-01-02 00:49

    One possibility is to use xUnit's MemberData attribute. A disadvantage with this approach is that this parameterized test appears in Visual Studio's Test Explorer as one test instead of two separate tests because collections lack xUnit's IXunitSerializable interface and xUnit hasn't added build-in serialization support for that type either. See xunit/xunit/issues/429 for more information.

    Here is a minimal working example.

    module TestModule
    
      open Xunit
    
      type TestType () =
        static member TestProperty
          with get() : obj[] list =
            [
              [| [0]; "a" |]
              [| [1;2]; "b" |]
            ]
    
        []
        []            
        member __.TestMethod (a:int list) (b:string) =
          Assert.Equal(1, a.Length)
    

    See also this similar question in which I give a similar answer.

提交回复
热议问题