unit-testing

pytest: How to get a list of all failed tests at the end of the session? (and while using xdist)

人盡茶涼 提交于 2021-02-18 08:59:27
问题 I would like to have a list of all the tests that have failed to be used at the end of session . Pytest lets you define a hook pytest_sessionfinish(session, exitstatus) , that is called at the end of the session, where I wish to have that list. session is a _pytest.main.Session instance that has the attribute items (type list ), but I couldn't find whether the each item in that list passed of failed. How can a list of all failed tests could be retrieved at the end of the session? How can it

NUnit: How to pass TestCaseData from a non-static method?

≯℡__Kan透↙ 提交于 2021-02-18 05:02:48
问题 my test fails because of : Message: The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method. This is my Code: const double MAX_DELTA = 0.01; Qv_ges qv_ges_NE; double Sum_Qv_ges_R_FL; Qv_ges Qv_ges_Quer; [SetUp] public void init() { qv_ges_NE = Din1946.Calc_Qv_ges_NE(205.7d); Sum_Qv_ges_R_FL = 15d + 15d + 15d + 15d + 15d + 10d + 10d + 10d + 10d + 10d + 10d + 10d; Qv_ges_Quer = Din1946.Calc_Qv_ges_Quer(qv_ges_NE, Sum_Qv_ges_R_FL); } public

Are mocks better than stubs?

我是研究僧i 提交于 2021-02-18 04:56:52
问题 A while ago I read the Mocks Aren't Stubs article by Martin Fowler and I must admit I'm a bit scared of external dependencies with regards to added complexity so I would like to ask: What is the best method to use when unit testing? Is it better to always use a mock framework to automatically mock the dependencies of the method being tested, or would you prefer to use simpler mechanisms like for instance test stubs? 回答1: As the mantra goes 'Go with the simplest thing that can possibly work.'

Are mocks better than stubs?

房东的猫 提交于 2021-02-18 04:56:17
问题 A while ago I read the Mocks Aren't Stubs article by Martin Fowler and I must admit I'm a bit scared of external dependencies with regards to added complexity so I would like to ask: What is the best method to use when unit testing? Is it better to always use a mock framework to automatically mock the dependencies of the method being tested, or would you prefer to use simpler mechanisms like for instance test stubs? 回答1: As the mantra goes 'Go with the simplest thing that can possibly work.'

How to convert an existing assembly to a ms unit test assembly?

隐身守侯 提交于 2021-02-17 21:16:04
问题 In Visual Studio 2010 Pro, how can I easily convert a classic assembly to a ms unit test assembly ? It there a flag to activate in the .csproj file ? 回答1: The problem is that test projects are "marked" on the project file - you can convert a class library to Test project follow these four simple steps: Unload the project (.prj) file and then open it for update. add the following line to the project C#: <Project> <PropertyGroup> <AssemblyName>....</AssemblyName> <!-- add this line below -->

How to convert an existing assembly to a ms unit test assembly?

耗尽温柔 提交于 2021-02-17 21:11:27
问题 In Visual Studio 2010 Pro, how can I easily convert a classic assembly to a ms unit test assembly ? It there a flag to activate in the .csproj file ? 回答1: The problem is that test projects are "marked" on the project file - you can convert a class library to Test project follow these four simple steps: Unload the project (.prj) file and then open it for update. add the following line to the project C#: <Project> <PropertyGroup> <AssemblyName>....</AssemblyName> <!-- add this line below -->

How to convert an existing assembly to a ms unit test assembly?

雨燕双飞 提交于 2021-02-17 21:10:56
问题 In Visual Studio 2010 Pro, how can I easily convert a classic assembly to a ms unit test assembly ? It there a flag to activate in the .csproj file ? 回答1: The problem is that test projects are "marked" on the project file - you can convert a class library to Test project follow these four simple steps: Unload the project (.prj) file and then open it for update. add the following line to the project C#: <Project> <PropertyGroup> <AssemblyName>....</AssemblyName> <!-- add this line below -->

Find method not working with EF6.1 mock

半城伤御伤魂 提交于 2021-02-17 03:59:07
问题 I've setup mocking using these msdn guidlelines: Testing with a mocking framework (EF6 onwards) var bsAc = _db.BusAcnts.FirstOrDefault(i => i.Id == 1); returns an account but var bsAc = _db.BusAcnts.Find(1); returns null when mocked. Find only fails when testing with a mock, it works fine in production. BusAcnt: (Id is the Primary Key) public class BusAcnt { public int Id { get; set; } ... } See the rest of my setup here. In debug I drilled down into Locals | this | MyDbContext and all the

Find method not working with EF6.1 mock

二次信任 提交于 2021-02-17 03:54:51
问题 I've setup mocking using these msdn guidlelines: Testing with a mocking framework (EF6 onwards) var bsAc = _db.BusAcnts.FirstOrDefault(i => i.Id == 1); returns an account but var bsAc = _db.BusAcnts.Find(1); returns null when mocked. Find only fails when testing with a mock, it works fine in production. BusAcnt: (Id is the Primary Key) public class BusAcnt { public int Id { get; set; } ... } See the rest of my setup here. In debug I drilled down into Locals | this | MyDbContext and all the

How to override a method in unit tests that is called from which the class being tested

折月煮酒 提交于 2021-02-16 18:34:13
问题 I am testing a class A's function func1. Func1 has a local variable of Class B and calls B's function func2. Code looks something like this: public Class A { public func1() { B object = new B(); int x = object.func2(something); } } When I am testing func1 in its unit tests, I don't want func2 to get called. So I am trying to do something like this in the test: B textObject = new B() { @override int func2(something) { return 5; } } But it is still calling the func2 in the class B. Please