I donβt know of any project templates for unit tests F # Silverlight 4 (I searched Online for templates using Add Project), so I use the standard library project F # Silverlight for unit tests (which are only file links to the main project files unit test). I am using xUnit.net Contrib for Silverlight . So everything compiles, but I donβt know how to run the tests! TestDriven.NET works for my regular unit test project, but not for this Silverlight unit test project. I tried using the regular xUnit GUI, but this will not work either. Any ideas?
Update
XUnit.net Contrib users It is recommended that you use Statlight as a standalone console runner. After adding System.Xml.Linq to my test project with Copy Local = true (my project is not needed, but Statlight), I was able to run the executable file, pointing to my test assembly without any errors, except that I couldnβt find tests.
I tried a lot of things to try and find tests. I gave explicit namespaces to my test modules. I tried the names of the test methods without spaces. I tried types with instance instances instead of functions in modules. I even tried the explicit flag --MethodsToTest
. Nothing works.
I am not sure if this will be a problem with Statlight or xUnit.net Contrib.
Note that I'm just trying to test a regular library that can be used by Silverlight projects and does not actually use any Silverlight features (indeed, I have no prior Silverlight experience!).
Update 2
I managed to add the regular xunit assembly to my project through NuGet (which "forces" it, even though it was not created for Silverlight), and then successfully run the tests using Testdriven.NET. But I'm not sure that this is a "hoax". Perhaps not because my tests are still compiled against the Silverlight version of my library ...?
Update 3
While I was still out of luck with the βlegalβ xunit solution, I was able to get Statlight to run some NUnit tests. In addition, it only recognizes tests for class instance methods, it does not recognize tests on module functions (although it can handle them just fine in a regular project). Bummer. (I asked a question in Statlight)
Update 4
I figured out a super hacky but workable solution to my problem, but still looking for something better. All my tests are Xunit tests (file links for a testing project other than Silverlight) written as functions in modules, but I cannot get Statlight to find any of the tests. However, I was able to get Statlight to run NUnit tests, which are written in the traditional way as members of a type instance. Thus, I was able to crack the following single NUnit test, which finds all the Xunit tests in the assembly and calls them (so I can only see one failed test as time, but other than that it works well):
namespace SilverlightTesting open Xunit open NUnit.Framework [<TestFixture>] type TestRunner() = let isFact (attr:obj) = match attr with | :? Xunit.FactAttribute as attr when attr.Skip = null -> true | _ -> false [<Test>] member this.Run () = let assm = System.Reflection.Assembly.GetExecutingAssembly() let tys = assm.GetTypes() let mutable count = 0 for ty in tys do let methods = ty.GetMethods() for mi in methods do let attrs = mi.GetCustomAttributes(false) if attrs |> Array.exists isFact then printf "running test `%s`..." mi.Name mi.Invoke(null,null) |> ignore printfn "passed" count <- count + 1 printfn "All %i tests passed." count