nunit

BDD for C# NUnit

拈花ヽ惹草 提交于 2019-12-18 13:12:24
问题 I've been using a home brewed BDD Spec extension for writing BDD style tests in NUnit, and I wanted to see what everyone thought. Does it add value? Does is suck? If so why? Is there something better out there? Here's the source: https://github.com/mjezzi/NSpec There are two reasons I created this To make my tests easy to read. To produce a plain english output to review specs. Here's an example of how a test will look: -since zombies seem to be popular these days.. Given a Zombie, Peson, and

replace Console.WriteLine in NUnit?

不想你离开。 提交于 2019-12-18 12:09:12
问题 haven't done much with NUnit before, but just wanted to dump some text to a window in a console type fashion. e.g. Console.WriteLine("... some information..."); that won't work of course because NUnit is driving things. I'm in the middle of building some unit tests, and want to dump a list of variable values for inspection during debug. It isn't strictly a unit test if I need to do this I admit that, but it would be convenient. 回答1: You can see Console output, you just have to select the

Nunit async test exception assertion

空扰寡人 提交于 2019-12-18 12:07:12
问题 I have a controller UserController with this action // GET /blah public Task<User> Get(string domainUserName) { if (string.IsNullOrEmpty(domainUserName)) { throw new ArgumentException("No username specified."); } return Task.Factory.StartNew( () => { var user = userRepository.GetByUserName(domainUserName); if (user != null) { return user; } throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, string.Format("{0} - username does not exist", domainUserName))); });

ExpectedException in nUnit gave me an error

﹥>﹥吖頭↗ 提交于 2019-12-18 12:06:06
问题 I'm new to using Testing Tools on the .NET Framework, so I downloaded it from NuGet with help from ReSharper. I am using this Quick Start to learn how to use nUnit. I had just copied the code and an error came up on this attribute: [ExpectedException(typeof(InsufficientFundsException))] //it is user defined Exception The error is: The type or namespace name 'ExpectedException' could not be found (are you missing a using directive or an assembly reference?) Why? And if I need such

The problem with NUnit and app.config

拜拜、爱过 提交于 2019-12-18 12:06:00
问题 When i run a simple test on connection to DB check i receive an error in NUnit: [Test] public void TestConn() { string connectionString = ConfigurationManager.ConnectionStrings["FertigungRead"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString); connection.Open(); Assert.AreEqual(ConnectionState.Open, connection.State); connection.Close(); } System.NullReferenceException : Object reference not set to an instance of an object. on line : connectionString =

Can I temporarily override DNS resolution within a .NET application?

狂风中的少年 提交于 2019-12-18 11:49:18
问题 I have some wrapper code that runs a set of NUnit tests that scan live websites for certain response codes. I'd like to run these tests against a different server. When running manually, I can do this by editing the /etc/hosts file in Windows\System32\drivers and temporarily setting www.mysite.com to 10.0.0.whatever Is there any way I can do the same within a .NET console application - temporarily override a DNS record or somehow intercept the resolution and return a different IP address?

Force NCover 1.5.8 to use v4 framework like testdriven.net does?

流过昼夜 提交于 2019-12-18 10:37:15
问题 I want to run coverage from the command line, but can't seem to get NCover 1.5.8 to instrument the code. It must be possible as when I run coverage tests with TestDriven.net it works. the difference seems to be that TD.NET is able to get NCover to use framework 4.0 (you get this in the log when it runs : MESSAGE: v4.0.30319 ) but from the command line I can't make it (I get this in the log : MESSAGE: v2.0.50727 ) So how can I make NCover play nice with nunit from the commandline, like it does

Running NUnit through Resharper 8 tests fail when crossing between projects due to AppDomain

こ雲淡風輕ζ 提交于 2019-12-18 10:26:35
问题 I recently updated to Resharper 8, and when I tried to run a suite of projects. These tests contain two suites of integration tests that both use IISExpress to run a website, make web requests and check the responses. Running them in isolation is successful, and running all the tests would previously succeed. However, after the upate the second set of tests to run would fail. Investigation has revealed the AppDomain.CurrentDomain.BaseDirectory is staying as the first test to run instead of

Are there NUnit Test Case Attributes for specifying Configuration

半腔热情 提交于 2019-12-18 08:58:10
问题 I am writing an NUnit test that I want run only in the Release configuration. Is there an elegant way of doing this with a test case attribute? Right now, I am surrounding the entire function block with compiler directives: I am using Nunit 2.5.6.10205. #if !DEBUG [Test] public void MyReleaseOnlyTest() { // stuff } #endif 回答1: You could use the [Category] attribute. If you mark release only tests with [Category("Release")] then exclude that category in your normal test run and include it in

MissingMethodException when testing a function that takes a function parameter

无人久伴 提交于 2019-12-18 08:46:27
问题 I am using FsUnit 2.1 (with NUnit 3.2) to write tests for an F# project. Here is a simple module: namespace Library1 module LibraryFunctions = let Execute f1 = f1() let Id x = x And here are my tests: namespace Tests open FsUnit open NUnit.Framework open Library1 [<TestFixture>] type Tests() = [<Test>] // Passes member x.``LibraryFunctions.Id should return the value``() = LibraryFunctions.Id 42 |> should equal 42 [<Test>] // Fails member x.``LibraryFunctions.Execute should return the result