nunit

NUnit 3.0 TestCase const custom object arguments

戏子无情 提交于 2019-12-12 10:49:23
问题 I've written the class SomeObject and I want to define a const instance of this object to keep/reuse in my TestCase s. How should I rewrite the code below to achieve this behavior? [TestFixture] public class SomeObjectTests { private const SomeObject item0 = new SomeObject(0.0); // doesn't work [TestCase(item0, ExpectedResult = 0.0)] public double TestSomeObjectValue(SomeObject so) { return so.Value; } [TestCase(item0, ExpectedResult = "0.0")] public string TestSomeObjectValueString

NUnit, testing against multiple cultures

五迷三道 提交于 2019-12-12 10:47:34
问题 Using NUnit I wish to run all the tests in a certain project against multiple cultures. The project deals with parsing data that should be culture neutral, to ensure this I would like to run every test against multiple cultures. The current solution I have is public abstract class FooTests { /* tests go here */ } [TestFixture, SetCulture ("en-GB")] public class FooTestsEN : FooTests {} [TestFixture, SetCulture ("pl-PL")] public class FooTestsPL : FooTests {} Ideally, I shouldn't have to

How to Unit Test HtmlHelper similar to “using(Html.BeginForm()){ }”

泄露秘密 提交于 2019-12-12 09:43:39
问题 Can somebody please suggest how I could write a Unit Test with Moq for following HtmlHelper method? public static HtmlTagBase GenerateTag<T>(this HtmlHelper htmlHelper , object elementData , object attributes) where T : HtmlTagBase { return (T)Activator.CreateInstance(typeof(T) , htmlHelper.ViewContext , elementData , attributes); } which you would use as follows (please note the using statement - this is causing me confusion): <%--Model is a type of ShareClass--%> <% using (Html.GenerateTag

Why testFixture instead of TestClass?

微笑、不失礼 提交于 2019-12-12 09:29:16
问题 There are three ways to organize unit tests: Test per Fixture, Class or Feature. But NUnit attribute for TestClass is called TestFixture. Are there any historical reasons for that? 回答1: The main historical reason is that NUnit started life as a straight port from JUnit and junit called it test fixture. NUnit 1.0 was before my time but I've been told it started out by renaming all of the .java files in JUnit to .cs files and trying to compile. It was fixed up from there and a UI was added.

Mocking DBSet, EF Model First

孤者浪人 提交于 2019-12-12 08:58:47
问题 As said in the title, I follow Model First method. So my Model classes are Automatically generated. If I want mock the DBContext derived MyModelContainer which contain DBSets of entity classes. Read some where that in order to unit test, you need to change it to IDBSet . Whether its possible to do it especially in a class that gets auto generated when I do "Run Custom Tool" is one concern. But as of now I modified it. But the real problem is: when I try to Stub MyModelContainer to return a

What is the equivalent of Java's default (package) access in C#?

天涯浪子 提交于 2019-12-12 08:46:33
问题 What is the equivalent of Java's default (package) access in C#? Is there one? Is there anyway to restrict access to a particular namespace? The Problem: I'm trying to restrict access to certain methods to just my NUnit tests - in JUnit I would do this by making the methods package access and having the test in the same package but under src/test/java instead of src/main/java. How can I achieve something similar in C#? Note: I can't make the methods internal because my tests are in a separate

how often should the entire suite of a system's unit tests be run?

倖福魔咒の 提交于 2019-12-12 08:28:54
问题 Generally, I'm still very much a unit testing neophyte. BTW, you may also see this question on other forums like xUnit.net, et cetera, because it's an important question to me. I apoligize in advance for my cross posting; your opinions are very important to me and not everyone in this forum belongs to the other forums too. I was looking at a large decade old legacy system which has had over 700 unit tests written recently (700 is just a small beginning). The tests happen to be written in

A .NET Unit Test without a parameterless constructor, to facilitate dependency injection

末鹿安然 提交于 2019-12-12 08:23:08
问题 I'm trying to have the unit tests not rely on calling container.Resolve<T>() for their dependencies. I'm currently using AutoFac 2.2.4, and tried xUnit.NET and NUnit , but both have this issue : No parameterless constructor defined for this object How do I get past this issue? Is it a particular unit testing framework that will support this, or just how said framework is configured? Should I not be doing this? Or can I set up the test class to work with the constructor that has it's only

Ms Test or NUnit?

不问归期 提交于 2019-12-12 05:49:45
问题 Is there any advantage to picking NUnit for unit/integration testing vs the built in MsTest? 回答1: They are pretty similar. Differences are subtle. NUnit has testcases for parametrized tests; MSTest does not. You can write [TestCase(1, "one)] [TestCase(2, "two)] [TestCase(3, "three)] [TestCase(4, "four)] public void CanTranslate(int number, string expectedTranslation) { var translation = _sut.Translate(number); translation.Should().Be.EqualTo(expectedTranslation); } rather than writing 4 tests

Reading an asset in a Xamarin NUnit test class

余生颓废 提交于 2019-12-12 05:30:09
问题 I want to read a mock RSS feed file to test against in a Xamarin NUnit test for an Android app. The test class has no context so I can't put the file in the Assets folder and do this: System.IO.Stream strIn = instanceOfAssetManager.Open(feedFile); It also has no ancestor, so I can't do this: System.IO.Stream strIn = this.Class.ClassLoader.ResourceAsStream(feedFile); Any suggestions how I can get to the jolly thing? This case solved a similar problem for a different platform/setup: Storing