xunit.net

Is Assert.Fail() considered bad practice?

独自空忆成欢 提交于 2019-12-03 04:00:58
问题 I use Assert.Fail a lot when doing TDD. I'm usually working on one test at a time but when I get ideas for things I want to implement later I quickly write an empty test where the name of the test method indicates what I want to implement as sort of a todo-list. To make sure I don't forget I put an Assert.Fail() in the body. When trying out xUnit.Net I found they hadn't implemented Assert.Fail. Of course you can always Assert.IsTrue(false) but this doesn't communicate my intention as well. I

How to run all tests in Visual Studio Code

怎甘沉沦 提交于 2019-12-02 18:45:57
The latest version of VS Code already provides an easy way of running a single test as pointed on Tyler Long's answer to the question Debugging xunit tests in .NET Core and Visual Studio Code . However, I am looking how can I run all tests contained in a test suite class in VS Code (without debug)? The only way I found was adding to launch.json a specific configuration as the following one, but which I can only run in debug (I would like to run it without debug): { "name": ".NET Core Xunit tests", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "/usr/local/share

Is Assert.Fail() considered bad practice?

自作多情 提交于 2019-12-02 17:48:53
I use Assert.Fail a lot when doing TDD. I'm usually working on one test at a time but when I get ideas for things I want to implement later I quickly write an empty test where the name of the test method indicates what I want to implement as sort of a todo-list. To make sure I don't forget I put an Assert.Fail() in the body. When trying out xUnit.Net I found they hadn't implemented Assert.Fail. Of course you can always Assert.IsTrue(false) but this doesn't communicate my intention as well. I got the impression Assert.Fail wasn't implemented on purpose. Is this considered bad practice? If so

How to use Microsoft.Extensions.Configuration.IConiguration in my XUnit unit testing

寵の児 提交于 2019-12-02 06:04:29
问题 In my Asp.net Core 2.0 application, I am trying to unit test my data service layer (.Net Standard Class Library) that uses the Microsoft.Extensions.Configuration.IConfiguration dependency injection. I am using XUnit and don't know how to pass IConfiguration from my unit test class. I tried the following implementation and getting the error Message: The following constructor parameters did not have matching fixture data: IConfiguration configuration. I am really new to the testing frameworks

.Net core testing with Xunit

懵懂的女人 提交于 2019-12-02 04:44:51
问题 This is the first time I am writing test case and I am not sort of stuck and not sure how to proceed further. I have the following API. In the below sample I have 2 endpoints which I want to perform testing. public class ValuesController : Controller { //This interface is used to setup dynamo db and connection to aws private IDynamoDbClientInitialization _clientAccessor; private static string dynamoDbTable = string.Empty; public ValuesController(IOptions<Dictionary<string, string>>

Getting code coverage in .net core, xUnit project

家住魔仙堡 提交于 2019-12-02 03:36:16
问题 I'm trying to get code coverage in .net core project using directions from https://github.com/Microsoft/vstest-docs/blob/master/docs/analyze.md#working-with-code-coverage Test are working correctly However, when I add code coverage option I get this error: Starting test execution, please wait... Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Object reference not set to an instance of an object. Maybe someone have experienced

How to use Microsoft.Extensions.Configuration.IConiguration in my XUnit unit testing

穿精又带淫゛_ 提交于 2019-12-02 03:07:27
In my Asp.net Core 2.0 application, I am trying to unit test my data service layer (.Net Standard Class Library) that uses the Microsoft.Extensions.Configuration.IConfiguration dependency injection. I am using XUnit and don't know how to pass IConfiguration from my unit test class. I tried the following implementation and getting the error Message: The following constructor parameters did not have matching fixture data: IConfiguration configuration. I am really new to the testing frameworks and don't even know if dependency injection can be used as I am trying to do in my code snippet. My Unit

.Net core testing with Xunit

▼魔方 西西 提交于 2019-12-02 01:41:48
This is the first time I am writing test case and I am not sort of stuck and not sure how to proceed further. I have the following API. In the below sample I have 2 endpoints which I want to perform testing. public class ValuesController : Controller { //This interface is used to setup dynamo db and connection to aws private IDynamoDbClientInitialization _clientAccessor; private static string dynamoDbTable = string.Empty; public ValuesController(IOptions<Dictionary<string, string>> appSettings, IDynamoDbClientInitialization clientAccessor) { var vals = appSettings.Value; dynamoDbTable = vals[

Getting code coverage in .net core, xUnit project

送分小仙女□ 提交于 2019-12-02 01:04:00
I'm trying to get code coverage in .net core project using directions from https://github.com/Microsoft/vstest-docs/blob/master/docs/analyze.md#working-with-code-coverage Test are working correctly However, when I add code coverage option I get this error: Starting test execution, please wait... Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Object reference not set to an instance of an object. Maybe someone have experienced it and could share knowledge how to fix it? When I tried to run powershell as an administrator this

Unit test for a collection of anonymous JSON objects

放肆的年华 提交于 2019-12-01 20:54:45
This question was inspired by this excellent example . I have ASP.NET Core MVC application and I am writing unit tests for the controller. One of the methods returns JsonResult with a collection of anonymous types. I can get to each element of the collection. I can also assert values in each element like this: Dictionary<int, string> expectedValues = new Dictionary<int, string> { { 1, "Welcome Tester"}, { 2, "Namaste Tester"}, { 3, "Privet Tester"}, { 4, "Labdien Tester"} }; foreach (dynamic value in jsonCollection) { dynamic json = new DynamicObjectResultValue(value); Assert.Equal