2016-08-01 8 views
7

.NETコアにnet45netstandard1.6というライブラリをいくつか持っており、それらをユニットテストしたいと思います。私はdotnet new -t xunittestを実行し、netcoreapp1.0を対象とする新しいテストプロジェクトを作成し、.NET Coreコードのみをテストするようにしました。.NET FrameworkとxUnitを使用して複数のフレームワークを対象とするユニットテストコード

私はまた、net45もターゲットにコンパイルしようとしましたが、テストの検出で一連のエラーが発生しました。私の質問は

単一のテストプロジェクトで両方の(多分後で)フレームワークを対象としたコードをテストする方法はありますか、私がターゲットとするそれぞれのテストプロジェクトを作るべきですか?

編集は:ここに私のproject.jsonとメッセージ私は取得しています:

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    "debugType": "portable" 
    }, 
    "dependencies": { 
    "xunit": "2.1.0" 
    }, 
    "testRunner": "xunit", 
    "frameworks": { 
    "net45": { 
     "frameworkAssemblies": { 
     "System.Runtime": "4.0.0.0" 
     } 
    }, 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.0.0" 
     }, 
     "System.Runtime.Serialization.Primitives": "4.1.1", 
     "dotnet-test-xunit": "2.2.0-preview2-build1029" 
     }, 
     "imports": [ 
     "dotnet5.4", 
     "portable-net451+win8" 
     ] 
    } 
    } 
} 

これらは、プロジェクトがコンパイルされると、私が取得エラーです:

dotnet-test Error: 0 : [ReportingChannel]: Waiting for message failed System.IO.IOException: Unable to read data om the transport connection: An established connection was aborted by the software in your host machine. ---> stem.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine 
    at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) 
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
    --- End of inner exception stack trace --- 
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
    at System.IO.Stream.ReadByte() 
    at System.IO.BinaryReader.ReadByte() 
    at System.IO.BinaryReader.Read7BitEncodedInt() 
    at System.IO.BinaryReader.ReadString() 
    at Microsoft.DotNet.Tools.Test.ReportingChannel.ReadMessages() 
>dotnet-test Error: 0 : Unhandled Exception: System.IO.IOException: Unable to read data from the transport nnection: An established connection was aborted by the software in your host machine. ---> stem.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine 
    at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) 
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
    --- End of inner exception stack trace --- 
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
    at System.IO.Stream.ReadByte() 
    at System.IO.BinaryReader.ReadByte() 
    at System.IO.BinaryReader.Read7BitEncodedInt() 
    at System.IO.BinaryReader.ReadString() 
    at Microsoft.DotNet.Tools.Test.ReportingChannel.ReadMessages() 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object ate) 
[ReportingChannel]: Error sending System.IO.IOException: Unable to write data to the transport connection: Cannot cess a disposed object. 
Object name: 'System.Net.Sockets.Socket'.. ---> System.ObjectDisposedException: Cannot access a disposed object. 
Object name: 'System.Net.Sockets.Socket'. 
    at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, cketError& errorCode) 
    at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) 
    at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
    --- End of inner exception stack trace --- 
    at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
    at System.IO.BinaryWriter.Write7BitEncodedInt(Int32 value) 
    at System.IO.BinaryWriter.Write(String value) 
    at Microsoft.DotNet.Tools.Test.ReportingChannel.Send(Message message) 
dotnet-test Error: 0 : System.IO.IOException: Unable to write data to the transport connection: Cannot access a sposed object. 
Object name: 'System.Net.Sockets.Socket'.. ---> System.ObjectDisposedException: Cannot access a disposed object. 
Object name: 'System.Net.Sockets.Socket'. 
    at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, cketError& errorCode) 
    at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) 
    at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
    --- End of inner exception stack trace --- 
    at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
    at System.IO.BinaryWriter.Write7BitEncodedInt(Int32 value) 
    at System.IO.BinaryWriter.Write(String value) 
    at Microsoft.DotNet.Tools.Test.ReportingChannel.Send(Message message) 
    at Microsoft.DotNet.Tools.Test.ReportingChannel.SendError(String error) 
    at Microsoft.DotNet.Tools.Test.ReportingChannel.SendError(Exception ex) 
    at Microsoft.DotNet.Tools.Test.DesignTimeRunner.HandleDesignTimeMessages(ProjectContext projectContext, tnetTestParams dotnetTestParams) 
    at Microsoft.DotNet.Tools.Test.DesignTimeRunner.DoRunTests(ProjectContext projectContext, DotnetTestParams tnetTestParams) 
    at Microsoft.DotNet.Tools.Test.BaseDotnetTestRunner.RunTests(ProjectContext projectContext, DotnetTestParams tnetTestParams, BuildWorkspace workspace) 
    at Microsoft.DotNet.Tools.Test.TestCommand.DoRun(String[] args) 

を、これで確定ライン

========== Discover test finished: 0 found (0:00:03.0417342) ========== 

私は1つのテストを持っていることは分かっています(少なくとも今のところは)。 xUnit .NET Core docsによると

​​
+0

どのようなエラーが表示されますか?また、エラーを再現できるように、あなたがしたことをより詳細に記述することができますか? – svick

+0

@svick私はエラーと 'project.json'データを追加して私の質問を編集しました。希望が役立つ – Luiso

答えて

5

あなたは単に追加することにより、net4xxnetcoreappの両方をターゲットにすることができます:

私はnet 45参照魔法のようにすべての作品を削除した場合しかし、ここで私の作業project.jsonです両方のフレームワークを一緒にproject.jsonファイルに保存します。 dotnet testを複数のフレームワークエントリで実行すると、すべてのフレームワークテストが順番に実行されます。

これは、あなたが(.NET 4.5のプロジェクトおよび.NETのコアプロジェクトなど)異なるプラットフォームをターゲット単一のテストプロジェクト参照とテストプロジェクトを持つことができるという意味ではありません。しかし、同じをプラットフォームとするを対象とするプロジェクトをテストできることを意味します。

{ 
    "dependencies": { 
    "NETStandard.Library": "1.6.0" 
    }, 

    "frameworks": { 
    "netstandard1.6": {}, 
    "net451": {} 
    }, 
    "version": "1.0.0-*" 
} 

私は私のテストプロジェクトでnet451netcoreapp1.0を対象とし、このクラスライブラリを参照することができます:たとえば、私は、.NET 4.5.1と.NETのコアの両方を対象としたクラスライブラリを持っている

dotnet testが実行されると、テストは(各プラットフォームのターゲットに一度)を2回実行されます
{ 
    "buildOptions": { 
    "debugType": "portable" 
    }, 
    "dependencies": { 
    "xunit": "2.2.0-beta2-build3300", 
    "dotnet-test-xunit": "2.2.0-preview2-build1029", 
    "NetStandardClassLibrary": { 
     "target": "project" 
    } 
    }, 
    "frameworks": { 
    "net451": {}, 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.0.0" 
     } 
     }, 
     "imports": [ 
     "dotnet5.4", 
     "portable-net451+win8" 
     ] 
    } 
    }, 
    "testRunner": "xunit", 
    "version": "1.0.0-*" 
} 

λ dotnet test 
Project NetStandardClassLibrary (.NETStandard,Version=v1.6) was previously compiled. Skipping compilation. 
Project XunitBothFrameworks (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation. 
xUnit.net .NET CLI test runner (64-bit .NET Core win81-x64) 
    Discovering: XunitBothFrameworks 
    Discovered: XunitBothFrameworks 
    Starting: XunitBothFrameworks 
    Finished: XunitBothFrameworks 
=== TEST EXECUTION SUMMARY === 
    XunitBothFrameworks Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0.244s 
Project NetStandardClassLibrary (.NETFramework,Version=v4.5.1) was previously compiled. Skipping compilation. 
Project XunitBothFrameworks (.NETFramework,Version=v4.5.1) was previously compiled. Skipping compilation. 
xUnit.net .NET CLI test runner (64-bit Desktop .NET win81-x64) 
    Discovering: XunitBothFrameworks 
    Discovered: XunitBothFrameworks 
    Starting: XunitBothFrameworks 
    Finished: XunitBothFrameworks 
=== TEST EXECUTION SUMMARY === 
    XunitBothFrameworks Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0.201s 
SUMMARY: Total: 2 targets, Passed: 2, Failed: 0. 

Visual Studio内でテストを実行しようとしたとき、私はあなたと同様のエラーメッセージを受け取りました。コマンドラインのdotnet testが問題なく動作したので、バグだと思う。

1

私にとって、project.jsonはうまく働いたので、私はcmdからテストを実行する必要はありませんでした。

{ 
    "version": "0.1.0-*", 
    "dependencies": { 
    "Moq": "4.5.22", 
    "xunit": "2.2.0-beta2-build3300", 
    "dotnet-test-xunit": "2.2.0-preview2-build1029", 
    "IntegraPay.Domain": { "version": "1.0.0-*","target": "project" }, 
    "Integrapay.RegistrationApplication": { "version": "", "target": "project" } 
    }, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": [ 
     "net451" 
     ], 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.0.0" 
     } 
     } 
    } 
    }, 
    "testRunner": "xunit" 
} 
関連する問題