xunit

How can I run xUnit Unit Tests with VS2015 Preview?

情到浓时终转凉″ 提交于 2019-12-04 22:30:37
I added the "xUnit.net runner for Visual Studio" v0.99.8 via Extensions Manager, but when I open the Test Explorer window, it does not seem to pick up any of my unit tests. Also, the Resharper 9 EAP does which is the only version of Resharper that supports VS2015 does seem yet to have the plugin for xUnit Test Runner. How then, can I run xUnit Unit Tests in VS2015 Preview? You can find the answer here: http://blogs.msdn.com/b/webdev/archive/2014/11/12/announcing-asp-net-features-in-visual-studio-2015-preview-and-vs2013-update-4.aspx Visual Studio supports running and debugging for ASP.NET 5

使用 xUnit 编写 ASP.NET Core 单元测试

女生的网名这么多〃 提交于 2019-12-04 22:10:41
还记得 .NET Framework 的 ASP.NET WebForm 吗?那个年代如果要在 Web 层做单元测试简直就是灾难啊。.NET Core 吸取教训,在设计上考虑到了可测试性,就连 ASP.NET Core 这种 Web 或 API 应用要做单元测试也是很方便的。其中面向接口和依赖注入在这方面起到了非常重要的作用。 本文就来手把手教你如何用 xUnit 对 ASP.NET Core 应用做单元测试。.NET Core 常用的测试工具还有 NUnit 和 MSTest,我本人习惯用 xUnit 作为测试工具,所以本文用的是 xUnit。 创建示例项目 先用 ASP.NET Core API 模板建一个应用。 模板为我们自动创建了一个 ValuesController,为了方便演示,我们只留其中一个 Get 方法: 1 public class ValuesController : ControllerBase 2 { 3 // GET api/values/5 4 [HttpGet("{id}")] 5 public ActionResult<string> Get(int id) 6 { 7 return "value"; 8 } 9 } 然后再添加一个 xUnit 单元测试项目: 模板自动为我们添加好了 xUnit 引用: 1 <ItemGroup> 2

Dependency Injection with XUnit and ASP.NET Core 1.0

南笙酒味 提交于 2019-12-04 21:40:57
问题 I am trying to figure out how I can use dependency injection with XUnit. My goal is to be able to inject my ProductRepository into my test class. Here is the code I am trying: public class DatabaseFixture : IDisposable { private readonly TestServer _server; public DatabaseFixture() { _server = new TestServer(TestServer.CreateBuilder().UseStartup<Startup>()); } public void Dispose() { // ... clean up test data from the database ... } } public class MyTests : IClassFixture<DatabaseFixture> {

.NET Core 3.0 单元测试与 Asp.Net Core 3.0 集成测试

人盡茶涼 提交于 2019-12-04 17:47:02
单元测试与集成测试 测试必要性说明 相信大家在看到单元测试与集成测试这个标题时,会有很多感慨,我们无数次的在实践中提到要做单元测试、集成测试,但是大多数项目都没有做或者仅建了项目文件。这里有客观原因,已经接近交付日期了,我们没时间做白盒测试了。也有主观原因,面对业务复杂的代码我们不知道如何入手做单元测试,不如就留给黑盒测试吧。但是,当我们的代码无法进行单元测试的时候,往往就是代码开始散发出坏味道的时候。长此以往,将欠下技术债务。在实践过程中,技术债务常常会存在,关键在于何时偿还,如何偿还。 上图说明了随着时间的推移开发/维护难度的变化。 测试框架选择 在 .NET Core 中,提供了 xUnit 、NUnit 、 MSTest 三种单元测试框架。 MSTest UNnit xUnit 说明 提示 [TestMethod] [Test] [Fact] 标记一个测试方法 [TestClass] [TestFixture] n/a 标记一个 Class 为测试类,xUnit 不需要标记特性,它将查找程序集下所有 Public 的类 [ExpectedException] [ExpectedException] Assert.Throws 或者 Record.Exception xUnit 去掉了 ExpectedException 特性,支持 Assert.Throws

Unit test WebApi2 passing header values

醉酒当歌 提交于 2019-12-04 17:01:50
I am working on a project using WebApi2. With my test project I am using Moq and XUnit. So far testing an api has been pretty straight forward to do a GET like [Fact()] public void GetCustomer() { var id = 2; _customerMock.Setup(c => c.FindSingle(id)) .Returns(FakeCustomers() .Single(cust => cust.Id == id)); var result = new CustomersController(_customerMock.Object).Get(id); var negotiatedResult = result as OkContentActionResult<Customer>; Assert.NotNull(negotiatedResult); Assert.IsType<OkNegotiatedContentResult<Customer>>(negotiatedResult); Assert.Equal(negotiatedResult.Content.Id,id); } Now

How to Write xUnit Test for .net core 2.0 Service that uses AutoMapper and Dependency Injection? [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-04 13:48:56
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm new to .net core/C# programming (coming over from Java) I have the following Service class the that uses dependency injection to get an AutoMapper object and a data repository object for use in creating a collection of SubmissionCategoryViewModel objects: public class SubmissionCategoryService :

Change pytest testsuite name in xml report

廉价感情. 提交于 2019-12-04 12:53:21
Because we started same tests with different interface, then take all reports and send them to jenkins. It's difficult to recognise with what interface we have errors. Before we use nose, it has parameter "--xunit-testsuite-name", has pytest analog? I want to change name of test suite in reports testsuite errors="0" failures="0" name=" pytest " skips="0" tests="12" time="103.702" to testsuite errors="0" failures="0" name=" inteface1 " skips="0" tests="12" time="103.702" You can add a junit_suite_name attribute to your Pytest config file since pytest 3.1: [pytest] junit_suite_name = my_suite

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();

boost unit tests with xUnit Plugin in Jenkins do not work

拟墨画扇 提交于 2019-12-04 09:05:38
I am not a C programmer, but i have to run boost tests on my Jenkins. Now I have installed the xUnit plugin in Jenkins. I added a post-build action : "Publish xUnit test result report" Then, in this post-build step I added : "BoostTest-1.x (default)" Now I have the following options to set: https://www.dropbox.com/s/wxcny55rz2bqk6r/boost_jenkins_options.png The options I set are random, so please help me, I don't understand anything and I didn't find some tutorials. I have not worked with boost unit test and not with the xUnit Jenkins plugin either. Can any one help me? edit: jenkins say me

Instantiating IOptions<> in xunit

[亡魂溺海] 提交于 2019-12-04 07:41:06
I'm trying to write an xunit test for a class (in a .net Core project) that looks something like: public Class FoodStore:IFoodStore { FoodList foodItems; public FoodStore(IOptions<FoodList> foodItems) { this.foodItems = foodItems; } public bool IsFoodItemPresentInList(string foodItemId) { //Logic to search from Food List } }` Note: FoodList is actually a json file, containing data, that is loaded and configured in the Startup class. How can I write an xunit test with appropriate dependency injection to test the IsFoodItemPresentInList method ? You could use OptionsWrapper<T> class to fake your