nunit

Passing dynamically generated value to NUnit Custom Attribute

╄→尐↘猪︶ㄣ 提交于 2019-12-24 18:27:07
问题 For our test scenarios - based on configuration of the application, we may want to either enable or disable a scenario. For this purpose, I created a custom IgnoreIfConfig Attribute like this : public class IgnoreIfConfigAttribute : Attribute, ITestAction { public IgnoreIfConfigAttribute(string config) { _config = config; } public void BeforeTest(ITest test) { if (_config != "Enabled") NUnit.Framework.Assert.Ignore("Test is Ignored due to Access level"); } public void AfterTest(ITest test) {

Testing the typesafe enum pattern in C#

拈花ヽ惹草 提交于 2019-12-24 18:03:50
问题 I am utilizing the "typesafe enum pattern" public class Level { public static readonly Level Low = new Level(0, "Low"); public static readonly Level Medium = new Level(1, "Medium"); public static readonly Level High = new Level(2, "High"); private int _value; private string name; private Level(int value, string name) { _value=value; _name=name; } } For testing purposes I need to create an invalid Level which I do with reflection. int id = -1; string value = "invalid"; var constructor = typeof

Run unit tests on dynamically created DLL

≯℡__Kan透↙ 提交于 2019-12-24 16:32:00
问题 I am thinking on how to implement this , and seems like my knowledge is too poor to understand the implementation. I have a code that compiles source code to DLL. Then I need somehow to run Unit test on this Dll , and check 3-4 methods inside. I am trying to run unit tests this way. CompilerResults compileResults = codeProvider.CompileAssemblyFromSource(compilerParameters, new string[] { sourceCode }); Assembly myAssembly = compileResults.CompiledAssembly; TestPackage testPackage = new

Unit test UWP app with NUnit on VS2015

混江龙づ霸主 提交于 2019-12-24 15:36:53
问题 I spent far too much time trying to run a basic NUnit test on a Microsoft Store app. I installed NUnit v3.0.1 and NUnit3TestAdapter on VS2015 Pro but I get the following which confirms that the test is not discovered: ------ Discover test started ------ NUnit Adapter 3.0.8.0 discovering tests is started Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in <project exe file> The NUnit 3.0 driver does not support the portable version of NUnit. Use a platform

NUnit not picking up the database connection string

浪子不回头ぞ 提交于 2019-12-24 13:34:12
问题 I have a project( SLR ) and an Nunit test project( SLR.Tests ) Every test of a method that interacts with the database fails with an "object not set to an instance of an object" exception on the line using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["isvConnectionString"].ToString())) Hard coding the connection string into the new statement works as expected, and calling the method in course of running the SLR project does not throw any exceptions. Therefore

ReSharper and NUnit's multiple domains

淺唱寂寞╮ 提交于 2019-12-24 13:08:43
问题 I recently had to enable this option in ReSharper: Use separate AppDomain for each assembly with tests Looking at the NUnit documentation, I suspect the option above executes NUnit with the parameter "domain/multiple", for which "a separate test domain is created for each assembly". Could you please confirm me that is true? 回答1: Yes, this option corresponds to the /domain=Multiple command line parameter. Note that ReSharper doesn't use the console runner. Instead it directly links the NUnit

NUnit tests don't appear in TFS choose test dialog using Visual Studio 2013 (C#)

限于喜欢 提交于 2019-12-24 12:38:06
问题 We are using Visual Studio 2013 and TFS for a new project started more than a month ago. I've chosen NUnit a test framework mainly because I was use to it using Resharper and Teamcity. During the build we have configured TFS to run the tests (using NUnitTestAdapter) and everything is OK. We have now discovered that you can link a unit test to a test case item in TFS and it seems a pretty good thing but in the choose test dialog of a test case item I am able to see only MsTest tests (with

C# Compare Lists with custom object but ignore order

旧街凉风 提交于 2019-12-24 12:14:23
问题 I'm trying to compare 2 Lists (wrapped in an object) containing custom objects. I don't care about the order, but if list 1 contains "1,2,3,4" then list 2 must and only contain those elements. E.g.: "4,2,3,1" Based on Compare two List<T> objects for equality, ignoring order ignoring-order I've used the Except and Any but it doesn't give me the desired results. If I use Assert.Equals it fails, but Assert.IsTry(list1.equals(list2)) succeeds. Further more if I remove the Equals and GetHashCode

NUnit error in xamarin

感情迁移 提交于 2019-12-24 12:00:20
问题 I am new to programming and learning C# using xamarin I am trying to do unit test but getting this error: 'TestFixtureAttribute' is obsolete:'The NUnit framework shipped with Mono is deprecated and will be removed in a future release. it was based on NUnit 2.4 which is long outdated. Please move to the NUnit NuGet package or some other form of acquiring NUnit.' thanks 回答1: Seems like you need to change the TextFixtureAttribute you reference. Mono itself has NUnit 2.4 included in it, so you

Retrieve Results from NUnit Programmatically

ぐ巨炮叔叔 提交于 2019-12-24 10:42:20
问题 Is it possible to retrieve the results of the Unit tests run using NUnit programmatically? If Yes then How? I have read that we can generate XML file using Nunit Console. Is there any other way around apart from generating and then parsing XML? 回答1: Yes, it is possible. You can use current test context to get name of test, status, working directory, etc [TearDown] public void TearDown() { var context = TestContext.CurrentContext; // context.Test.Name // context.Result.Status } 来源: https:/