nunit

Run unit tests in different appdomain with NUnit

老子叫甜甜 提交于 2019-12-17 16:22:28
问题 I seem to be having an issue, the application we're using uses a Ninject kernel, and contains a particular configuration that's gathered with contents of the WCF call (username, token...). Based on that a particular configuration the user is assigned rights on the app, this is shielded through a particular instance in the Ninject kernel. We cannot just recompose the Ninject kernel, what we'd like to do is run a couple of Nunit tests, but run each of them in a separate app domain (recreating

nunit tests throwing exception only when run as part of tfs msbuild process

情到浓时终转凉″ 提交于 2019-12-17 16:17:44
问题 I'm building and deploying a solution from Visual Studio 2015 using TFS 2012 without issues. I have decided to incorporate my unit tests as part of the prerequisites for the build process. Independent of the msbuild process, the unit tests run without issue and succeed; however, when I incorporate them as part of my build process I am getting the following exception in my build: Exception NUnit.Core.UnsupportedFrameworkException, Exception thrown executing tests in D:\Builds\4\PA1111CE

Moq.Mock<T> - how to set up a method that takes an expression

不羁岁月 提交于 2019-12-17 15:25:18
问题 I am Mocking my repository interface and am not sure how to set up a method that takes an expression and returns an object? I am using Moq and NUnit. Interface: public interface IReadOnlyRepository : IDisposable { IQueryable<T> All<T>() where T : class; T Single<T>(Expression<Func<T, bool>> expression) where T : class; } Test with IQueryable is already set up, but don't know how to set up the T Single: private Moq.Mock<IReadOnlyRepository> _mockRepos; private AdminController _controller;

Problem in reading connection string from App.Config when using NUnit 2.5.2

时光怂恿深爱的人放手 提交于 2019-12-17 13:09:04
问题 I'm using Microsoft Visual Studio 2005 with Enterprise Library 3.1. I have a data access layer which is a separate visual studio class library project. I wrote unit tests in a another class library and trying to call the data access method, but I keep getting PSMCP.Dal.Tests.DataManagerTests.GetAAAReturnsDataReader: System.NullReferenceException : Object reference not set to an instance of an object. at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name,

Problem in reading connection string from App.Config when using NUnit 2.5.2

醉酒当歌 提交于 2019-12-17 13:06:33
问题 I'm using Microsoft Visual Studio 2005 with Enterprise Library 3.1. I have a data access layer which is a separate visual studio class library project. I wrote unit tests in a another class library and trying to call the data access method, but I keep getting PSMCP.Dal.Tests.DataManagerTests.GetAAAReturnsDataReader: System.NullReferenceException : Object reference not set to an instance of an object. at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name,

How do you test private methods with NUnit?

≯℡__Kan透↙ 提交于 2019-12-17 10:35:11
问题 I am wondering how to use NUnit correctly. First i created a separate Test-Project that uses my main project as reference. But in that case i am not able to test private methods. My guess was that i need to include my testcode into my main code?! - That doesn't seem to be the correct way to do it. (I dislike the idea of shipping code with tests in it.) How do you test private methods with NUnit? 回答1: Generally, unit testing addresses a class's public interface, on the theory that the

Is there a free Visual Studio addin for Nunit?

杀马特。学长 韩版系。学妹 提交于 2019-12-17 10:16:01
问题 I'm cheap and don't want to pay for ReSharper or TestDriven.NET, is there a free visual Studio addin for NUnit? 回答1: You can create a blank project (Choose console application for example) and in the property of the project you can select DEBUG tag and select "Start External Program". Put the path of Nunit. Than, in the start option, the command line arguments select the DLL that contain all your test (mine is always in the nunit\bin...). Than select "enable unmanaged code debugging" and you

How do I use Assert.Throws to assert the type of the exception?

我怕爱的太早我们不能终老 提交于 2019-12-17 10:11:53
问题 How do I use Assert.Throws to assert the type of the exception and the actual message wording. Something like this: Assert.Throws<Exception>( ()=>user.MakeUserActive()).WithMessage("Actual exception message") The method I am testing throws multiple messages of the same type, with different messages, and I need a way to test that the correct message is thrown depending on the context. 回答1: Assert.Throws returns the exception that's thrown which lets you assert on the exception. var ex = Assert

MSTest Equivalent for NUnit's Parameterized Tests?

我的梦境 提交于 2019-12-17 09:53:27
问题 NUnit supports a feature where you can specify a set of data inputs for a unit test to be run multiple times. [RowTest] [Row(1001,1,2,3)] [Row(1,1001,2,3)] [Row(1,2,1001,3)] public void SumTests(int x, int y, int z, int expected) { ... } What's the best way to accomplish this same type of thing using MSTest? I can't find a similar set of attributes. 回答1: Would this help? This week I was adding some unit tests to a project that is managed by TFS, so I decided to use the "core" unit testing

Unit test for thread safe-ness?

帅比萌擦擦* 提交于 2019-12-17 08:05:34
问题 I've written a class and many unit test, but I did not make it thread safe. Now, I want to make the class thread safe, but to prove it and use TDD, I want to write some failing unit tests before I start refactoring. Any good way to do this? My first thought is just create a couple threads and make them all use the class in an unsafe way. Do this enough times with enough threads and I'm bound to see it break. 回答1: There are two products that can help you there: Microsoft Chess Typemock Racer