xUnit tests under F# : It looks like you're trying to execute an xUnit.net unit test ('System.ArgumentException' occurred in xunit.runner.utility.dll)

▼魔方 西西 提交于 2020-01-25 11:53:29

问题


0. My setup is as follows

Visual Studio 2012 Ultimate, update 3, v.11.0.60610.01
Visual F# 2012 04940-004-0038003-02527
TestDriven.Net 3.5 Beta 3 Personal

1. What I have in packages.config:

    <?xml version="1.0" encoding="utf-8"?>
    <packages>
      <package id="FsUnit.xUnit" version="1.2.1.2" targetFramework="net45" />
      <package id="xunit" version="1.9.1" targetFramework="net45" />
    </packages>

2. What I ran: xunit.installer.exe

3. This is what the packages folder looks like

\packages\FsUnit.xUnit.1.2.1.2
\packages\xunit.1.9.1
\packages\repositories.config
\packages\FsUnit.xUnit.1.2.1.2\Lib
\packages\FsUnit.xUnit.1.2.1.2\tools
\packages\FsUnit.xUnit.1.2.1.2\FsUnit.xUnit.1.2.1.2.nupkg
\packages\FsUnit.xUnit.1.2.1.2\FsUnit.xUnit.1.2.1.2.nuspec
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net20
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net40
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net20\FsUnit.CustomMatchers.dll
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net20\FsUnit.CustomMatchers.XML
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net20\FsUnit.Xunit.dll
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net20\FsUnit.Xunit.xml
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net20\NHamcrest.dll
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net40\FsUnit.CustomMatchers.dll
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net40\FsUnit.CustomMatchers.XML
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net40\FsUnit.Xunit.dll
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net40\FsUnit.Xunit.xml
\packages\FsUnit.xUnit.1.2.1.2\Lib\Net40\NHamcrest.dll
\packages\FsUnit.xUnit.1.2.1.2\tools\install.ps1
\packages\xunit.1.9.1\lib
\packages\xunit.1.9.1\xunit.1.9.1.nupkg
\packages\xunit.1.9.1\xunit.1.9.1.nuspec
\packages\xunit.1.9.1\lib\net20
\packages\xunit.1.9.1\lib\net20\xunit.dll
\packages\xunit.1.9.1\lib\net20\xunit.dll.tdnet
\packages\xunit.1.9.1\lib\net20\xunit.installer.exe
\packages\xunit.1.9.1\lib\net20\xunit.runner.msbuild.dll
\packages\xunit.1.9.1\lib\net20\xunit.runner.tdnet.dll
\packages\xunit.1.9.1\lib\net20\xunit.runner.utility.dll
\packages\xunit.1.9.1\lib\net20\xunit.xml

4. My test file:

module MyTesting

open Xunit
open FsUnit.Xunit

[<Fact>]
let ``please work``() = 123

And I am still getting this:

------ Test started: Assembly: MyTesting.dll ------

It looks like you're trying to execute an xUnit.net unit test.

For xUnit 1.5 or above (recommended):
Please ensure that the directory containing your 'xunit.dll' reference also contains xUnit's
test runner files ('xunit.dll.tdnet', 'xunit.runner.tdnet.dll' etc.)

For earlier versions:
You need to install support for TestDriven.Net using xUnit's 'xunit.installer.exe' application.

You can find xUnit.net downloads and support here:
http://www.codeplex.com/xunit

A question:

What am I doing wrong?

UPDATE:

This is what is says when I run in the debug mode:

'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Program Files (x86)\TestDriven.NET 3\ProcessInvocation86.exe'
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Program Files (x86)\TestDriven.NET 3\TestDriven.TestRunner.Server.dll'
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Program Files (x86)\TestDriven.NET 3\TestDriven.TestRunner.dll'
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Program Files (x86)\TestDriven.NET 3\TestDriven.Framework.dll'
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Mine\MyProject\packages\xunit.1.9.1\lib\net20\xunit.runner.tdnet.dll'
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Mine\MyProject\bin\Debug\MyProject.Testing.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Mine\MyProject\packages\xunit.1.9.1\lib\net20\xunit.runner.utility.dll'
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'xunit.runner.utility.{Dynamic}'
A first chance exception of type 'System.ArgumentException' occurred in xunit.runner.utility.dll
The thread 'TestRunnerThread' (0x13b0) has exited with code 0 (0x0).
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Program Files (x86)\TestDriven.NET 3\AdHoc\TestDriven.AdHoc.dll'
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Mine\MyProject.Testing\bin\Debug\MyProject.Testing.dll', Symbols loaded.
'ProcessInvocation86.exe' (Managed (v4.0.30319)): Loaded 'C:\Mine\MyProject\MyProject.Testing\bin\Debug\xunit.dll'
The thread 'TestRunnerThread' (0x504) has exited with code 0 (0x0).
The program '[1136] ProcessInvocation86.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

回答1:


I can't repro this.

Here is what I did:

  1. Open VS2013, TD.NET 3.5 RC
  2. Create an F# project, Windows -> Library (.NET 4.5)
  3. Ran "install-package xunit -version 1.9.1" from the Package Manager Console
  4. Ran "install-package fsunit.xunit -version 1.2.1.2" from the Package Manager Console
  5. Replaced the contents of Library1.fs with:
module FsTestSample

open Xunit
open FsUnit.Xunit

[<Fact>]
let ``please work``() = 123

I placed the cursor inside "please work" and right clicked, then clicked on "Run Test(s)". The test ran, with this output:

------ Test started: Assembly: FsTestSample.dll ------

1 passed, 0 failed, 0 skipped, took 0.50 seconds (xUnit.net 1.9.1 build 1600).

I even changed "= 123" to "= 123 / 0" just to verify that the test failed with a divide by zero exception (it did).




回答2:


You have two problems:

  1. your Fact is broken:-

    If you hover over the

    please work

    bit, you'll see something like: unit -> int

    For a Fact to be picked up by an xUnit runner, it needs to yield `unit (void).

    Hence, one key thing to get right first is to not return anything. In other words, replace your 123 with () (or an Assertion).

    You can guard against this by putting a :unit stipulation on the test:-

    [<Fact>]
    let ``please work`` () : unit = 123
    

    This will force a compilation error.

  2. TestDriven.NET cannot find the xunit.tdnet modules

    Either try the VS-based runner which should work as long as it's installed and xunit.dll is getting to your output dir or look at the docs for your version of TD.NET for detailed troubleshooting notes (exec summary is if the .tdnet file was in your out dir or you undo and redo the xunit.installer from the folder containing the packages it should just work, esp if you are on latest)




回答3:


Finally got it. So the reason turned out to be that the path to folder that contained the project had a # sign in it (..\F#..). I hope this can save you some headache. If it doesn't and the reason is different here is what you gotta do:

  1. In Visual Studio go Debug >> Exceptions...
  2. Enable breaking on Common Language Runtime Exceptions by setting a corresponding checkbox in the Thrown column.
  3. Run your test in the Debug mode via the TD.NET: [Right click on the test function] >> Test with >> Debugger
  4. The debugger should stop at whatever problem (exception) you have.


来源:https://stackoverflow.com/questions/20341250/xunit-tests-under-f-it-looks-like-youre-trying-to-execute-an-xunit-net-unit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!