How to run F# Silverlight Library project holding xUnit.net Contrib based unit tests?
I am unaware of开发者_如何学JAVA any project templates for F# Silverlight 4 unit tests (I searched Online for templates through Add Project), so I am using the standard F# Silverlight Library project to hold my unit tests (which are just file links to the main unit test project files). 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 normal unit test project but not this Silverlight unit test project. I tried to use the normal xUnit GUI runner but that doesn't work either. Any ideas?
Update
The xUnit.net Contrib folks recommended using Statlight as a standalone console runner. After adding System.Xml.Linq to my test project with Copy Local=true (my project doesn't need it but Statlight does) I was able to run the executable pointing at my test assembly without any errors except it was unable to find any tests.
I tried lots of things to try and allow the tests to be found. I gave explicit namespaces to my test modules. I tried test method names without spaces. I tried types with instance members instead of functions in modules. I even tried the explicit --MethodsToTest
flag. Nothing works.
I'm not sure if this would be a problem with Statlight or xUnit.net Contrib.
Please note that I am merely trying to test a plain library which can be consumed by Silverlight projects and doesn't actually use any Silverlight features (indeed, I don't have any prior Silverlight experience!).
Update 2
I was able to add the normal xunit assembly to my project through NuGet (which "forces" it in despite not being built for Silverlight) and then run the tests successfully using Testdriven.NET. But I'm not sure if this is "cheating". Perhaps not because my tests are still compiled against the Silverlight version of my library...?
Update 3
While I still haven't had any luck with a "legit" xunit solution, I was able to get Statlight to run some NUnit tests. Except, it only recognizes tests on instance methods of a class, it doesn't recognize tests on functions of a module (while it can handle these just fine in a normal project). Bummer. (I filed an issue with Statlight)
Update 4
I've figured out a super hacky but workable solution to my problem, still looking for something better though. All of my tests are Xunit tests (file links to the non-Silverlight test project) written as functions in modules but I can't 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 fashion as instance members of a type. Thus I was able to whip up the following single NUnit test which finds all the Xunit tests in the assembly and invokes them (so I can only see one failing test as a time, but other than that it does work 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
I've used lighthouse sucessfully in the past, but I don't know if it works with xUnit I used it with mstest. Currently working with AGUnit which is statlight based resharper plugin combined with nunit, though it has difficulty with dll only silverlight projects--they work if you make it into a xap file.
精彩评论