xunit.net

How to parametrize a xunit class fixture?

别等时光非礼了梦想. 提交于 2021-02-20 18:42:29
问题 xUnit offers the concept of (shared) class fixtures as explained in Shared Context between Tests. What I didn't figure out so far is if there is a way of parametrizing such class fixtures. For example, what if the DatabaseFixture should be enriched with some test data which depends on the test it's being run against? A test class might want to insert test data but only once and then run all its tests against that database (fixture). In other words, what if the // ... initialize data in the

Are there Parameterized Test Fixtures for xunit?

风格不统一 提交于 2021-02-18 22:15:45
问题 Does xunit.net support "Parameterized Test Fixtures" like nunit (see example code below). Note I'm not looking for IUseFixture<T> or [Theory] because these do not provide the same functionality as Parameterized Test Fixtures [TestFixture("hello", "hello", "goodbye")] [TestFixture("zip", "zip")] [TestFixture(42, 42, 99)] public class ParameterizedTestFixture { private string eq1; private string eq2; private string neq; public ParameterizedTestFixture(string eq1, string eq2, string neq) { this

How to Mock config file in .Net Core with xUnit

跟風遠走 提交于 2021-02-11 15:00:44
问题 I want to mock the config file values in .NET Core. I am using xUnit for unit test. I am using application insight. I use config file for configuration. Now I want to mock that .cs config file in my unit test case. var configurationPackage = statelessServiceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config"); var appInsightsSection = configurationPackage.Settings.Sections["AppInsightsConfig"]; var appInsightsInstrumentationKey = appInsightsSection.Parameters[

How to Mock config file in .Net Core with xUnit

≡放荡痞女 提交于 2021-02-11 15:00:03
问题 I want to mock the config file values in .NET Core. I am using xUnit for unit test. I am using application insight. I use config file for configuration. Now I want to mock that .cs config file in my unit test case. var configurationPackage = statelessServiceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config"); var appInsightsSection = configurationPackage.Settings.Sections["AppInsightsConfig"]; var appInsightsInstrumentationKey = appInsightsSection.Parameters[

XUnit - InvalidOperationException : Solution root could not be located using application root

爱⌒轻易说出口 提交于 2021-02-08 06:20:07
问题 I have a Web-API .NET Core 2.2 project and I am trying to do integration tests on it. I have followed the guide from Microsoft. The tests pass when starting them from the test runner and from the command line, they should be configured correctly, I am able to call the controllers via the WebApplicationFactory - HTTP client. I have disabled shadow copy via xunit.runner.json So far so good. I am trying to use Azure DevOps to deploy my project and at the release step, I've added a test step that

NUnit SetUpFixture attribute equivalent in xUnit?

拈花ヽ惹草 提交于 2021-02-07 03:19:16
问题 In nUnit, SetUpFixture allowed me to run some code before any tests. Is there anything like that when using xUnit? From nUnit documentation: This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace. 回答1: xUnit's comparison table shows that where you would use [TestFixtureSetUp] in NUnit, you make your test fixture class implement IUseFixture<T> . If [TestFixtureSetUp] isn't the attribute you're looking for,

NUnit SetUpFixture attribute equivalent in xUnit?

时光毁灭记忆、已成空白 提交于 2021-02-07 03:18:56
问题 In nUnit, SetUpFixture allowed me to run some code before any tests. Is there anything like that when using xUnit? From nUnit documentation: This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace. 回答1: xUnit's comparison table shows that where you would use [TestFixtureSetUp] in NUnit, you make your test fixture class implement IUseFixture<T> . If [TestFixtureSetUp] isn't the attribute you're looking for,

NUnit SetUpFixture attribute equivalent in xUnit?

余生颓废 提交于 2021-02-07 03:18:28
问题 In nUnit, SetUpFixture allowed me to run some code before any tests. Is there anything like that when using xUnit? From nUnit documentation: This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace. 回答1: xUnit's comparison table shows that where you would use [TestFixtureSetUp] in NUnit, you make your test fixture class implement IUseFixture<T> . If [TestFixtureSetUp] isn't the attribute you're looking for,

How to refer to test files from Xunit tests in Visual Studio?

元气小坏坏 提交于 2021-02-05 20:48:38
问题 We’re using Xunit for testing. We’re running our tests via the built-in Visual Studio 2013 Test Runner, using the Xunit plugin. The issue is that some of the tests need to refer to files on the filesystem . It seems that Xunit (or the VS Test Runner—not sure which), copies the assembles, but not any supporting files in the bin directory, to another directory before executing the tests, hence our test files are not found. [The MS Testing framework specifies attributes for listing files to be

How to unit test a function in .NET Core 3.1 that uses ExecuteSqlRawAsync to call a stored procedure?

南笙酒味 提交于 2021-01-29 06:02:11
问题 I'm writing an API in ASP.NET Core 3.1, using EF Core to access a SQL Server database. I have a function in the API that needs to call a stored procedure with several input parameters and an output parameter. A simplified version of this function is below. I am using a DbContext with .UseInMemoryDatabase() for other tests, but the in memory database cannot be used with stored procedures. (This solution is database first, not code first. It would be possible to change the stored procedure if