xunit

Display OpenCover results in TFS 2015 build Summary

我的梦境 提交于 2019-11-28 10:25:21
I have generated my xml coverage file as part of CI build on the TFS server using vNext 2015 build definition. How would one display the results in the TFS 2015 summary ? Either using the xml report or the html generated using the ReportGenerator. You need to convert the results produced by OpenCover to a format which can be parsed by TFS. One way to do this would be to use the OpenCoverToCoberturaConverter NuGet package. Once you have that, you can use the Publish Code Coverage Results build step. I have described the whole process on my blog . In “TFS 2015 - Update 2” this is possible by

Assert an Exception using XUnit

天涯浪子 提交于 2019-11-28 07:07:21
I am a newbie to XUnit and Moq. I have a method which takes string as an argument.How to handle an exception using XUnit. [Fact] public void ProfileRepository_GetSettingsForUserIDWithInvalidArguments_ThrowsArgumentException() { //arrange ProfileRepository profiles = new ProfileRepository(); //act var result = profiles.GetSettingsForUserID(""); //assert //The below statement is not working as expected. Assert.Throws<ArgumentException>(() => profiles.GetSettingsForUserID("")); } Method under test public IEnumerable<Setting> GetSettingsForUserID(string userid) { if (string.IsNullOrWhiteSpace

Python unittests in Jenkins?

耗尽温柔 提交于 2019-11-28 02:42:51
How do you get Jenkins to execute python unittest cases? Is it possible to JUnit style XML output from the builtin unittest package? sample tests: tests.py: # tests.py import random try: import unittest2 as unittest except ImportError: import unittest class SimpleTest(unittest.TestCase): @unittest.skip("demonstrating skipping") def test_skipped(self): self.fail("shouldn't happen") def test_pass(self): self.assertEqual(10, 7 + 3) def test_fail(self): self.assertEqual(11, 7 + 3) JUnit with pytest run the tests with: py.test --junitxml results.xml tests.py results.xml: <?xml version="1.0"

.net core + xunit 集成测试

白昼怎懂夜的黑 提交于 2019-11-28 01:36:59
xunit地址: https://github.com/xunit/xunit 一、利用请求来测试接口,主要是测试webapi控制器方法 ①添加xunit项目 ,然后引用我们的主项目,nuget: Microsoft.AspNetCore.TestHost, Microsoft.AspNetCore.Mvc.Testing(不然找不到接口地址), Microsoft.NETCore.App, Microsoft.AspNetCore.App , Microsoft.EntityFrameworkCore.InMemory 使用内存数据库进行测试 ②在主项目中写几个测试接口 ③测试项目中创建 TestServerFixture public class TestServerFixture : IDisposable { private readonly TestServer _testServer; public HttpClient Client { get; } public TestServerFixture() { var bulild = new WebHostBuilder().UseStartup<Startup1>(); _testServer = new TestServer(bulild); Client = _testServer.CreateClient();

xUnit Async Test Not Working Properly

被刻印的时光 ゝ 提交于 2019-11-27 23:36:53
问题 We have been using xUnit Framework in our project as test framework since the begining. Currently there are 2200+ unit tests in project and everything seems fine. But yesterday i decided to run unit tests at CI builds and nightly builds. Fighting with team build controller to run xunit tests for 1-2 hours i succeed to run tests. But there was a problem, there 22 warning abouts tests like below, - Xunit.Sdk.EqualException: Assert.Equal() Failure or - System.ArgumentNullException: Value cannot

How to mock ActionExecutingContext with Moq?

别等时光非礼了梦想. 提交于 2019-11-27 13:16:01
问题 I am trying to test the following filter: using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Filters; namespace Hello { public class ValidationFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (!filterContext.ModelState.IsValid) { filterContext.Result = new BadRequestObjectResult(filterContext.ModelState); } } } } I am trying to mock the ActionFilterAttribute using Moq. I am using Mvc 6.0.0-rc1 My first try: var context =

Entity Framework Core: Log queries for a single db context instance

让人想犯罪 __ 提交于 2019-11-27 12:44:26
Using EF Core (or any ORM for that matter) I want to keep track of the number of queries the ORM makes to the database during some operation in my software. I've used SQLAlchemy under Python earlier, and on that stack this is faily easy to set up. I typically have unit tests that assert on the number of queries made for a scenario, against an in-memory SQLite database. Now I want to do the same thing using EF Core, and have looked at the Logging documentation . In my test setup code I do as the documentation says: using (var db = new BloggingContext()) { var serviceProvider = db

Net Core: Execute All Dependency Injection in Xunit Test for AppService, Repository, etc

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:08:54
I am trying to implement Dependency Injection in Xunit test for AppService. Ideal goal is to run the original application program Startup/configuration, and use any dependency injection that was in Startup, instead of reinitializing all the DI again in my test, thats the whole Goal in question. Update: Mohsen's answer is close. Need to update couple syntax/requirement errors to work. For some reason, original application works and can call Department App Service. However, it cannot call in Xunit. Finally got Testserver working using Startup and Configuration from original application. Now

Assert an Exception using XUnit

谁说我不能喝 提交于 2019-11-27 01:26:08
问题 I am a newbie to XUnit and Moq. I have a method which takes string as an argument.How to handle an exception using XUnit. [Fact] public void ProfileRepository_GetSettingsForUserIDWithInvalidArguments_ThrowsArgumentException() { //arrange ProfileRepository profiles = new ProfileRepository(); //act var result = profiles.GetSettingsForUserID(""); //assert //The below statement is not working as expected. Assert.Throws<ArgumentException>(() => profiles.GetSettingsForUserID("")); } Method under

xUnit : Assert two List<T> are equal?

人盡茶涼 提交于 2019-11-26 19:47:20
问题 I'm new to TDD and xUnit so I want to test my method that looks something like: List<T> DeleteElements<T>(this List<T> a, List<T> b); Is there any Assert method that I can use ? I think something like this would be nice List<int> values = new List<int>() { 1, 2, 3 }; List<int> expected = new List<int>() { 1 }; List<int> actual = values.DeleteElements(new List<int>() { 2, 3 }); Assert.Exact(expected, actual); Is there something like this ? 回答1: xUnit.Net recognizes collections so you just need