nunit

How to use mock which is not passed to real object

瘦欲@ 提交于 2020-06-27 04:02:57
问题 I have service CarTankService as shown below. It has Add method which i want to test. To be more detailed i would like to check whether AddTank (inside Add) will be reached. public class CarTankService : ICarTankService { private readonly ITankQuery _tankQuery; private readonly CarClient _carClient; public CarTankService(ITankQuery tankQuery) { _tankQuery = tankQuery; _carClient = new CarClient(); } public ObservableCollection<CarTank> GetTanks() => _carClient.Tanks; public void

Specflow: maintain one Examples table for many Scenario Outlines

左心房为你撑大大i 提交于 2020-06-12 04:46:25
问题 Is there a way of keeping the "Examples" data table in a separate file from the Scenario Outline? What I am trying to achieve is to run the entire scenario once per browser, one after the other. I have this working with the following feature: Feature: OpenGoogleInChrome Scenario Outline: Open Google in Chrome Given a browser '<browser>' When the browser points to 'https://www.google.co.uk/' Then the title should be 'Google' Examples: | browser | | Chrome | | Edge | | Firefox | But this would

NUnit 3: Forbid tests to run in parallel

主宰稳场 提交于 2020-06-09 10:03:32
问题 I have the latest NUnit(3.2.0) installed and I have all my tests run in parallel. It might look like desirable behavior but I didn't ask for it and actually it broke some of my tests. I have some initialization in [OneTimeSetUp] which is thread-dependent and it seems I can't do anything to force NUnit to run my tests sequentially. I've read the documentation and it states that by default tests aren't run in parallel but in fact they are! Moreover, I've tried to add the following attribute:

Socket Server and NUnit: Thread.Sleep

风格不统一 提交于 2020-05-30 08:00:08
问题 I am writing a socket server and client classes, which I'm testing through NUnit. I wrote a process, which is checking all clients, if they are still connected. For this process I created a Thread, but what I want is to run this check only like every 5 seconds. My first intension was to use Thread.Sleep() . When I am ending the test, I am running the Stop method on server, which interrupt all active threads, which is causing that Thread was interruted from a waiting state. I find out there is

I need to capture Unit test case result and pass it into an array. How can I do that?

北战南征 提交于 2020-05-30 07:03:26
问题 I need to capture Unit test case result that is pass/fail in form of 1 and 2 and save it into an array for multiple test cases results. 1 for pass and 2 for fail. What if i need to save only one test case result? How can I do that? I am using Nunit C#. Using selenium webdriver. Here is the glimpse of my code [Priority(1)] [TestMethod] public void search() { Testlog.Info("Test ID:001); Testlog.Info("Select customer from cutomer dropdown"); var dc = gmethods.GetSelectElement(WDriver, dpo

How to fix the following issue with test not being executed in Visual Studio

元气小坏坏 提交于 2020-05-28 09:48:11
问题 When Ever I try to run my test it shows the following. NUnit3TestExecutor converted 8 of 8 NUnit test cases The active test run was aborted. Reason: Test host process crashed : Process is terminated due to StackOverflowException. I have a Helper class which has few methods here are the methods. public class Helper { public void Asserts(HttpWebResponse response) { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); } [AttributeUsage(AttributeTargets.Property)] public class

How to fix the following issue with test not being executed in Visual Studio

我们两清 提交于 2020-05-28 09:47:29
问题 When Ever I try to run my test it shows the following. NUnit3TestExecutor converted 8 of 8 NUnit test cases The active test run was aborted. Reason: Test host process crashed : Process is terminated due to StackOverflowException. I have a Helper class which has few methods here are the methods. public class Helper { public void Asserts(HttpWebResponse response) { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); } [AttributeUsage(AttributeTargets.Property)] public class

什么是单元测试,集成测试,冒烟测试和回归测试?

做~自己de王妃 提交于 2020-05-02 04:30:50
问题: What are unit tests, integration tests, smoke tests, and regression tests? 什么是单元测试,集成测试,冒烟测试和回归测试? What are the differences between them and which tools can I use for each of them? 它们之间有什么区别,我可以为每个工具使用哪些工具? For example, I use JUnit and NUnit for unit testing and integration testing. 例如,我将JUnit和NUnit用于单元测试和集成测试。 Are there any smoke testing or regression testing tools? 有烟雾测试或回归测试工具吗? 解决方案: 参考一: https://stackoom.com/question/2BI8/什么是单元测试-集成测试-冒烟测试和回归测试 参考二: https://oldbug.net/q/2BI8/What-are-unit-tests-integration-tests-smoke-tests-and-regression-tests 来源: oschina 链接: https://my.oschina.net/u

.NET 单元测试的艺术&单元测试之道C#版

拟墨画扇 提交于 2020-04-15 09:40:04
【推荐阅读】微服务还能火多久?>>> 特性标签 [DataSource] 标识用来测试的数据源 关于C#程序的单元测试 目录 1.单元测试概念 2.单元测试的原则 3.单元测试简单示例 4.单元测试框架特性标签 5.单元测试中的断言Assert 6.单元测试中验证预期的异常 7.单元测试中针对状态的间接测试 8.单元测试在MVC模式中的实现 8.单元测试相关参考 9.示例源代码下载 志铭-2020年1月23日 11:49:41 1.单元测试概念 什么是单元测试? 单元测试(unit testing)是一段自动化的代码,用来调用被测试的方法或类,而后验证基于该方法或类的逻辑行为的一些假设。 简而言之说:单元测试是一段代码(通常一个方法)调用另外一段代码,随后检验一些假设的正确性。 在过程化编程中,一个单元就是单个程序、函数、过程等; 对于面向对象编程, 最小单元就是方法 ,包括基类(超类)、抽象类、或者派生类(子类)中的方法。 为什么要单元测试? 单元测试的目标是隔离程序部件并证明这些单个部件是正确的。单元测试在软件开发过程的早期就能发现问题。 在代码重构或是修改的时候,可以根据单元测试快速验证新修改的代码的正确性,换句话说为了方便系统的后期维护升级! 单元测试某种程度上 相当于系统的文档 。借助于查看单元测试提供的功能和单元测试中如何使用程序单元

How can I save test case result in a variable whether it is passed or not after the test case execution is done?

落爺英雄遲暮 提交于 2020-04-06 17:38:40
问题 I am using selenium webdriver in visual studio Using NUNIT C#. The code of test case is public class MainProjectFile { private IWebDriver WDriver; private log4net.ILog Testlog; [TestInitialize] public void wd() { WDriver = Helper.GetWebDriver(helperconst.browserType.Chrome); Testlog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); } [Priority(1)] [TestMethod] public void search() { Testlog.Info("Test ID:001, This test will select the criteria and update