nunit

Getting started with automated integration/unit testing in an existing code base

﹥>﹥吖頭↗ 提交于 2019-12-10 07:46:57
问题 Background: We have been handed over a very large codebase (1.4 million lines) that is primarily in C#. The application consists primarily of asp.net 2.0 style asmx web services accessing data in a SQL server 2008 database and also in various XML files. There are no existing automated tests in place. We have an automated nightly build in place (CC.NET). We want to introduce some level of automated testing, but refactoring in granular level unit tests for this amount of code seems unlikely.

How can I mock ServiceStack IHttpRequest

大城市里の小女人 提交于 2019-12-10 06:31:37
问题 I'm trying to get a unit test working for a service that is injecting items into the IHttpRequest.Items, using a request filter: this.RequestFilters.Add((req, res, dto) => { // simplified for readability... var repo = container.Resolve<IClientRepository>(); var apiKey = req.Headers["ApiKey"]; // lookup account code from api key var accountcode = repo.GetByApiKey(apiKey); req.Items.Add("AccountCode", accountCode); }); My service uses that dictionary item: public class UserService :

NUnit Rollback After Test

徘徊边缘 提交于 2019-12-10 03:59:41
问题 I am pretty new to NUnit (and automated testing in general). I have recently done some Ruby On Rails work and noticed that in my test suite, when I create objects (such as a new user) and commit them during course of the suite, they are never committed to the database so that I can run the test over and over and not worry about that user already existing. I am now trying to accomplish the same thing in NUnit, but I am not quite sure how to go about doing it. Do I create a transaction in the

Run SpecFlow tests without Visual Studio

戏子无情 提交于 2019-12-10 02:30:43
问题 I would like out QA team to be able to run SpecFlow tests. I would like them to be able to change values and append more scenarios. These appended scenarios will have matching step definitions, so they only need to modify the features. The QA team does not have access to Visual Studio. Is it possible to achieve this without using Visual Studio? We are currently using MS Test but we are willing to use NUnit if that will help. 回答1: Yes - there is a 'simple' way. Since SpecFlow merely generates

How to unit test code that is highly complex behind the public interface

一个人想着一个人 提交于 2019-12-10 02:06:06
问题 I'm wondering how I should be testing this sort of functionality via NUnit. Public void HighlyComplexCalculationOnAListOfHairyObjects() { // calls 19 private methods totalling ~1000 lines code + comments + whitespace } From reading I see that NUnit isn't designed to test private methods for philosophical reasons about what unit testing should be; but trying to create a set of test data that fully executed all the functionality involved in the computation would be nearly impossible. Meanwhile

NUnit Assert.Equals What am I missing?

走远了吗. 提交于 2019-12-10 01:57:08
问题 Assert.Equals() never calls Equals() operator == operator != Am I missing something? I have implemented IEquatable but still the methods are never being called while using nunit. if (objectA != objectB) Assert.Fail(); //doesnt fail if (!objectA.Equals(objectB)) Assert.Fail(); //doesnt fail Assert.AreEqual(objectA, objectB); //fail UPDATE I should have been clearer. public class Entity { public int ID { get; set; } } var objectA = new Entity() { ID = 1 }; var objectB = new Entity() { ID = 1 };

nunit3 how to include test category in command line

六月ゝ 毕业季﹏ 提交于 2019-12-10 01:24:07
问题 nunit3-console TestData.dll /include:SmokeTests but with nunit v3 I get back: Invalid argument: /include:SmokeTests I try to check command line parameters here http://nunit.org/index.php?p=consoleCommandLine&r=3.0 but page does not exist. Anyone know what has changed? 回答1: So if anyone searching how to do this in NUNIT3: --where "cat == SmokeTests" --noresult helped by @omer727 link! 回答2: Link provided by @omer727 is broken, here is another one: https://github.com/nunit/docs/wiki/Console

How do I pass an Action into a TestCase

故事扮演 提交于 2019-12-10 00:16:34
问题 I have an NUnit test [TestCase(...)] public void test_name(Action onConfirm) { ... } What I want to do is pass an Action into this test in the TestCase attribute, but no matter what I try keeps failing. I tried to put () => SomeDummyMethodIDefined() directly into the TestCase and that didn't work. I created an Action Action DummyAction = () => SomeDummyMethodIDefined(); and pass DummyAction into the TestCase and that didn't work. Is there a way to do this? 回答1: This is a very rough example

NUnit test with Application loop in it hangs when Form is created before it

浪尽此生 提交于 2019-12-09 22:40:20
问题 I have a few tests with WebBrowser control wrapped with MessageLoopWorker as described here: WebBrowser Control in a new thread But when another test creates user control or form, the test freezes and never completes: [Test] public async Task WorksFine() { await MessageLoopWorker.Run(async () => new {}); } [Test] public async Task NeverCompletes() { using (new Form()) ; await MessageLoopWorker.Run(async () => new {}); } // a helper class to start the message loop and execute an asynchronous

NUnit Integration With Microsoft Test Manager

故事扮演 提交于 2019-12-09 19:43:45
问题 I can import test cases to Microsoft Test Manager from unit test assembly created in Visual Studio using tcm testcase import command.When I try to import test cases but using NUnit assembly the command fails saying "No Tests found to import".Is there another way by which I can import test cases created in Nunit to Microsoft Test Manager? 回答1: We were able to pick up our NUnit tests fine using tcm to import to MTM, by adding a TestMethodAttribute to our NUnit test methods. For example: