xunit

mock atLeastOnce with concrete value, the rest not important

点点圈 提交于 2019-12-23 09:48:41
问题 The question is in PHP , but applies to any language using the xUnit framework. I want a mock, that expects 140 calls to method jump . I need to verify, that at least once there is a call with 500 as parameter. I don't care if all the calls are 500, but I need at least one that is called with 500. $mock = $this->getMock('Trampoline', ['jump']); $mock->expects($this->atLeastOnce()) ->method('jump') ->with($this->equalTo(500)) ->will($this->returnValue(true)); $sportsman->setTramploine($mock);

What is the attribute in Xunit that's similar to TestContext in Visual studio tests?

谁都会走 提交于 2019-12-23 09:32:45
问题 We are migrating from visual studio tests to xunit.. In VStests we can access run time test parameters using TestContext. I am looking to set a global variable in the tests supplied at run time from command line using msbuild. Can someone help in finding out the TestContext equivalent in xunit? 回答1: There is no TestContext in XUnit. I could not find a canonical way to deal with environment parameters when running the tests, so I relied on a JSON file. E.g.: { "Browser": "Chrome", "BasePath":

running xunit tests included in a .NET Standard 1.6 library

ぐ巨炮叔叔 提交于 2019-12-23 09:17:33
问题 I just created a netstandard library in Visual Studio 2017 and added references to xunit and xunit.runner.visualstudio , but the VS Test Explorer and Resharper 2017 EAP 3 are not recognizing any tests. I've seen: Unit testing a .NET Standard 1.6 library but project.json is gone and csproj is back in place. What do I have to do, to be able to run the unit tests included in a netstandard library? Library.csproj <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard1.6<

Locals missing during debugging in Visual Studio 2015

。_饼干妹妹 提交于 2019-12-23 07:22:05
问题 Issue Locals only displays this variable while debugging, other local variables are not available in Locals or Watch but can be re-evaluated in Intermediate Window in Visual Studio Brief I'm debugging an Xunit test for some code I am writing. The library I am testing targets ASP.NET Core RC1. Here is my project.json : { "authors": [ "Matthew Abbott" ], "commands": { "test": "xunit.runner.dnx" }, "description": "Provides tests for the Fx.Content.Composer package", "dependencies": { "xunit": "2

AutoFixture mixing PropertyData with multiple entries and AutoData (using AutoMoqCustomization)

一个人想着一个人 提交于 2019-12-23 03:15:09
问题 I've looked at both of these similar SO questions: AutoFixture: PropertyData and heterogeneous parameters AutoFixture CompositeDataAttribute does not work with PropertyDataAttribute And they're awesome and get me nearly there. But both examples use only one entry in the emitted IEnumerable PropertyData (i.e.: yield return new object[] { 2, 4 }; -- see: https://stackoverflow.com/a/16843837/201308) This works, but it blows up whenever I want to do test over more than one object[] test data. I

AutoFixture mixing PropertyData with multiple entries and AutoData (using AutoMoqCustomization)

左心房为你撑大大i 提交于 2019-12-23 03:15:09
问题 I've looked at both of these similar SO questions: AutoFixture: PropertyData and heterogeneous parameters AutoFixture CompositeDataAttribute does not work with PropertyDataAttribute And they're awesome and get me nearly there. But both examples use only one entry in the emitted IEnumerable PropertyData (i.e.: yield return new object[] { 2, 4 }; -- see: https://stackoverflow.com/a/16843837/201308) This works, but it blows up whenever I want to do test over more than one object[] test data. I

Lambda expression as inline data in xUnit

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 18:27:08
问题 I'm pretty new to xUnit and here's what I'd like to achieve: [Theory] [InlineData((Config y) => y.Param1)] [InlineData((Config y) => y.Param2)] public void HasConfiguration(Func<Config, string> item) { var configuration = serviceProvider.GetService<GenericConfig>(); var x = item(configuration.Config1); // Config1 is of type Config Assert.True(!string.IsNullOrEmpty(x)); } Basically, I have a GenericConfig object which contains Config and other kind of configurations, but I need to check that

Lambda expression as inline data in xUnit

南笙酒味 提交于 2019-12-22 18:27:01
问题 I'm pretty new to xUnit and here's what I'd like to achieve: [Theory] [InlineData((Config y) => y.Param1)] [InlineData((Config y) => y.Param2)] public void HasConfiguration(Func<Config, string> item) { var configuration = serviceProvider.GetService<GenericConfig>(); var x = item(configuration.Config1); // Config1 is of type Config Assert.True(!string.IsNullOrEmpty(x)); } Basically, I have a GenericConfig object which contains Config and other kind of configurations, but I need to check that

Problems installing NoseXUnit

≡放荡痞女 提交于 2019-12-22 13:59:03
问题 I tried to install NoseXUnit using pip. Trying to run nosetests with it ends with the following error message: # nosetests --with-nosexunit /usr/lib/python2.7/site-packages/nose-1.3.0-py2.7.egg/nose/plugins/manager.py:395: RuntimeWarning: Unable to load plugin nosexunit = nosexunit.plugin:NoseXUnit: (coverage 3.7.1 (/usr/lib/python2.7/site-packages), Requirement.parse('coverage==2.85')) RuntimeWarning) Usage: nosetests [options] nosetests: error: no such option: --with-nosexunit So it seems

Mocking DbEntityEntry

删除回忆录丶 提交于 2019-12-22 10:50:04
问题 I am writing unit tests for my Generic Repository layer but i have some problems with DbEntityEntry . My Update method is like below. public virtual void Update(TEntity entityToUpdate) { var entity = dbSet.Find(context.Entry<ITrackedEntity>(entityToUpdate).Entity.Id); context.Entry(entity).CurrentValues.SetValues(entityToUpdate); } As you can see, context.Entry<TEntity>(TEntity entity) method is invoked by caller. So while unit tests this code throws null exception. I had tried to mock