xunit2

Invalid cast exception Xunit deserialization error

守給你的承諾、 提交于 2020-06-29 05:13:09
问题 When trying to run a test case that uses the xunit framework through Visual Studio I am currently getting the following error. System.InvalidCastException HResult=0x80004002 Message=Specified cast is not valid. Source=xunit.execution.desktop StackTrace: at Xunit.Serialization.XunitSerializationInfo.GetValue[T](String key) in C:\Dev\xunit\xunit\src\common\XunitSerializationInfo.cs:line 40 at Xunit.Sdk.XunitTestCase.Deserialize(IXunitSerializationInfo data) in C:\Dev\xunit\xunit\src\xunit

Referencing standard dlls from a .NET Core XUnit project

人走茶凉 提交于 2019-12-18 07:03:47
问题 I am using the latest version of XUnit and I followed these steps to get the Class Library (.NET Core) project started. All other libraries throughout my entire solution are only using 4.6.1 so I changed the frameworks section in project.json to the following: { "frameworks": { "net461": { "dependencies": { "Microsoft.NETCore.Platforms": "1.0.1-rc2-24027" } } } } and everything works fine inside of my solution. I am able to run tests and all references to other libraries work fine even though

Why is the Visual Studio 2015/2017/2019 Test Runner not discovering my xUnit v2 tests

会有一股神秘感。 提交于 2019-12-17 04:43:04
问题 Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. UPDATE: Adding a 2019; the discovery/runner integration mechanism is same as per 2017 & 2015, so the key things that can go wrong are the same. I've read Why is the xUnit runner not finding my tests, which covers reasons xUnit would never be able to find your tests but my problem is different - I'm

Integration Testing with AutoMapper fails to initialise configuration

狂风中的少年 提交于 2019-12-11 02:21:06
问题 Frameworks & Packages .NETCoreApp 1.1 Xunit 2.2.0 AutoMapper 6.0.2 Microsoft.AspNetCore.TestHost 1.1.1 Microsoft.NET.Test.Sdk 15.0.0 Integration Test public class ControllerRequestsShould { private readonly TestServer _server; private readonly HttpClient _client; public ControllerRequestsShould() { _server = new TestServer(new WebHostBuilder() .UseContentRoot(Constants.apiProjectRoot) .UseStartup<Startup>() .UseEnvironment(Constants.testingEnvironment)); _client = _server.CreateClient();

Reconfigure dependencies when Integration testing ASP.NET Core Web API and EF Core

穿精又带淫゛_ 提交于 2019-12-09 02:18:31
问题 I'm following this tutorial Integration Testing with Entity Framework Core and SQL Server My code looks like this Integration Test Class public class ControllerRequestsShould : IDisposable { private readonly TestServer _server; private readonly HttpClient _client; private readonly YourContext _context; public ControllerRequestsShould() { // Arrange var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .BuildServiceProvider(); var builder = new DbContextOptionsBuilder

xUnit.net v2 not discovering .NET Core Tests in Visual Studio 2015

亡梦爱人 提交于 2019-12-08 15:57:30
问题 I am really frustrated with this issue. I have already tried changing the version numbers but no tests are showing in the test explorer. In the test output window I can see this output Starting Microsoft.Framework.TestHost [C:\Users\sul\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin\dnx.exe --appbase "path to test project" Microsoft.Framework.ApplicationHost --port 63938 Microsoft.Framework.TestHost --port 63954 list ] Unable to start Microsoft.Framework.TestHost ========== Discover test

XUnit Test Constructor dependence injection with Autofac

…衆ロ難τιáo~ 提交于 2019-12-07 16:11:48
问题 I am implementing Xunit with Autofac, I could make it work by below code: using (var scoped = DbFixture.Container.Resolve<UserReponsitory>()) { var result = (scoped.GetAll()).ToList().Count(); Assert.Equal(2, result); } But I want to inject UserReponsitory to test method instead of using DbFixture.Container.Resolve . Is it possible to make below code work? UnitTest1.cs namespace XUnitTestPro { public class UnitTest1:IClassFixture<DbFixture> { private IUserReponsitory _userReponsitory; public

XUnit Test Constructor dependence injection with Autofac

浪子不回头ぞ 提交于 2019-12-05 20:24:29
I am implementing Xunit with Autofac, I could make it work by below code: using (var scoped = DbFixture.Container.Resolve<UserReponsitory>()) { var result = (scoped.GetAll()).ToList().Count(); Assert.Equal(2, result); } But I want to inject UserReponsitory to test method instead of using DbFixture.Container.Resolve . Is it possible to make below code work? UnitTest1.cs namespace XUnitTestPro { public class UnitTest1:IClassFixture<DbFixture> { private IUserReponsitory _userReponsitory; public UnitTest1(IUserReponsitory userReponsitory) { _userReponsitory = userReponsitory; } [Fact] public void

Collection fixture won't inject

浪子不回头ぞ 提交于 2019-12-04 16:05:25
问题 I'm using xUnit 2.0 collection fixtures to share a common database setup/teardown between a number of different test classes. The fixture also provides some helper properties, so I'm injecting it into each test class. I recreated the example in the docs, but when I run the test, it fails immediately with: The following constructor parameters did not have matching fixture data: IntegrationTestFixture fixture This seems to happen regardless of whether I'm using xUnit Facts or Theories, or which

How to implement XUnit descriptive Assert message?

怎甘沉沦 提交于 2019-12-04 09:56:02
问题 Context in XUnit github I found this: Add Assert.Equal(expected, actual, message) overload #350 (so a developer ask for a non existing overload see below) Quote from the answer: We are a believer in self-documenting code; that includes your assertions. (so the XUnit team rejects it) OK, I got it. I also believe the self documenting code. Still I can not find out this use case: Sample // Arrange // Create some external soap service client and its wrapper classes // Act // client.SomeMethod();