nunit

OpenCover testing tool usage in Visual Studio 2013

自古美人都是妖i 提交于 2019-12-10 18:25:07
问题 I am trying to use OpenCover for a calculator application, written in C#. I have opened it in Visual Studio 2013 and installed the OpenCover and Report Generation packages using the package manager console. I cannot understand the other commands to continue. Specifically what does it mean by -target<target application> ? I cannot understand a single step to continue. 回答1: When you install OpenCover it would/should have presented you with a readme.txt that provides a link to the wiki http:/

Mocking WebSecurity provider

╄→гoц情女王★ 提交于 2019-12-10 18:24:44
问题 I'm trying to create some simple unit tests for my controllers and I've come across an issue. I'm using the new membership provider in MVC 4 and getting the WebSecurity.CurrentUserId and storing that value in the database. When I run my unit tests against this it's failing and I think I have track this back to the fact that the WebSecurity isn't being mocked at all. Here's my code if it helps at all, The Controller [HttpPost] public ActionResult Create(CreateOrganisationViewModel viewModel) {

Can you pass data to a test fixture just like you pass data to test cases?

本小妞迷上赌 提交于 2019-12-10 17:49:27
问题 Can you pass data to a NUnit3 test fixture just like you pass data to test cases? Would it even make sense to do this? (run a suite (fixture class) based on a parameter) 回答1: Absolutely! If there's a limited amount of parameters you need to pass in, you can just put these in the normal [TestFixture] attribute, and they will be passed to the constructor of the TestFixture. e.g. [TestFixture("hello", "hello", "goodbye")] [TestFixture("zip", "zip", "zap")] public class ParameterizedTestFixture {

Unit Testing a Custom Validation Filter

 ̄綄美尐妖づ 提交于 2019-12-10 17:39:14
问题 I have the following attribute: public class ValidateModelAttribute : ActionFilterAttribute { public override void OnActionExecuting(HttpActionContext actionContext) { if (actionContext.ModelState.IsValid == false) { actionContext.Response = actionContext.Request.CreateErrorResponse( HttpStatusCode.BadRequest, actionContext.ModelState); } } } I have this generic extension method for Determining whether the attribute is applied to a method or not public static bool ActionHasFilter(this

Selenium - Modal dialog present - how to accept information?

可紊 提交于 2019-12-10 17:38:41
问题 I have a following problem. After Submit some date on page I have a modal dialog like on the picture: I want to click "ENTER" to go through that modal but it does not work. I have following code: driver.FindElement(By.CssSelector("input.submit")).Click(); Actions action = new Actions(driver); action.SendKeys(OpenQA.Selenium.Keys.Enter); After click on continue manually test go back to next page. I must go through this modal to continue the test. Any ideas how to solve this problem? 回答1: I

How can my code detect at run time if it compiled for x86 or for Any CPU

邮差的信 提交于 2019-12-10 17:31:19
问题 I have a lot of integration tests which read expected results from files. My tests access those files by relative paths. Relative paths are one level of depth different for x86 vs Any CPU. For example, when my tests run under x86, they need to read the following file "../../TestResults/MyTest.csv", but under Any CPU they need to access "../TestResults/MyTest.csv" So far I have the following constant in every test fixture: private const string platformDependentPrefix = ""; If I run my tests

how to debug tests in .net

情到浓时终转凉″ 提交于 2019-12-10 17:31:11
问题 I want to debug my tests, to examine every test to see where exactly is fail. I was using coderush which is awesome tool but my trial period 1month is expired. Any suggestion is welcome. 回答1: As Mark says, if you find a tool really useful, buy it. Personally I use ReSharper to run my tests, but that's a personal choice. I also use NCrunch, which is free (and wonderful). I believe you can use that for debugging too. However, you can debug with the NUnit GUI - just attach the debugger to the

How to mock An Abstract Base Class

帅比萌擦擦* 提交于 2019-12-10 17:26:31
问题 I have a base class called "Question" and several child classes such as "TrueFalse", "MultipleChoice", "MatchPairs" etc... The base class has methods with logic that all of the child classes use, such as sending off scores and raising events. I have set my unit tests up for the child classes but I am not sure how I can setup unit tests for the methods in the base class. I did some searching and I understand I need to create a Mock of the class but I am not sure how to do this as I have only

Multiple assertions when unit testing constructor?

混江龙づ霸主 提交于 2019-12-10 17:19:13
问题 I'm trying to unit test a class with 2 constructors. Each constructor has multiple parameters that set public properties. My question is, should I have only 2 unit tests with multiple asserts to check that each property was set OR a test for each parameter for each constructor? Public Person(string name, string phone, string birthday) { name = name; phone = phone; birthday = birthday; } Public Person(string name) : this(name, null, null) {} 回答1: The operation that you are testing is that the

Why can't the NUnit Test Adapter find my FsUnit tests?

大城市里の小女人 提交于 2019-12-10 17:17:38
问题 I'm using Visual Studio Professional 2015 and I have version 2.0.0.0 of the NUnit Test Adapter installed. It doesn't discover any tests on building the following code: namespace SmallestDivisibleIntegers module Core = let f n = [2..4] |> List.map (fun x -> x + n - n % x) module Tests = open FsUnit open NUnit.Framework open Core [<Test>] let ``Correct answers`` () = f 1 |> should equal [2; 3; 4] f 4 |> should equal [6; 6; 8] f 43 |> should equal [44; 45; 44] f 123 |> should equal [124; 126;