Writing tests for script files in F #

I have some functions with a script file, setup.fsx I would like to test them. xUnit and similar functions need proven functions to be part of the assembly.

So, I am thinking of renaming my script from setup.fsx to the setup.fs extension, and then loading it from another script file. But then my script depends on

#r "System.Xml"
#r "System.Xml.Linq"

which I would have to specify in the calling script (away from where the dependency actually occurs)

Is there a way to integrate script-based tests in xUnit worflow? What organization is proposed for writing tests for script files?

(Maybe we need an extension of the visual studio for tests in scripts, not in the assembly.)

+5
source share
2 answers

fsx script Visual Studio, setup.fsx (, fs) , script script Visual Studio , .

test.fsx :

module Demo
#r "System.Xml.Linq.dll"
open System.Xml.Linq

let test () = 
    let d = XDocument(XElement(XName.Get("foo")))
    d.ToString()

module Name ( ), fsx. , , test.fs:

module Main
open Demo    
test() |> printfn "%A"

, . , , xUnit ( , #r test.fsx, ):

fsc.exe --target:library test.fsx test.fs

, Visual Studio, , ( ), - fsproj :

<Compile Include="..\Eslewhere\In\Your\Project\Tree\File.fsx">
  <Link>File.fsx</Link>
</Compile>

, fsx " ", "", "", . , .

:, , , dll, . fsx, (select, Alt + Enter). , fsx , . , , dll.

+2

, , , *.fs. *.fsx script #load *.fs (#load #include C/++).

F #, *.fs, <Link> ( ), DLL.

0

All Articles