Using decimal values in DataRowAttribute
It’s because decimal is not a primitive type The solution is to use strings and then convert your parameters in your test.
It’s because decimal is not a primitive type The solution is to use strings and then convert your parameters in your test.
The method with the ClassInitialize attribute runs once for all the tests in the class. An instance of the class is created each time a test is run, so it has to be static in order to only run once. If you want to initialize for every test, then you can use the TestInitialize attribute, … Read more
Assuming you are using MSTest, you can use System.Diagnostics.Trace.WriteLine(“Hello World”); To output whatever you’d like. It will show up in the full results of the test runner.
Microsoft has provided a helper class CollectionAssert. [TestMethod] public void VerifyArrays() { int[] actualArray = { 1, 3, 7 }; CollectionAssert.AreEqual(new int[] { 1, 3, 7 }, actualArray); }
List item speed is same, but MsTest may be a bit slower because it creates folder for test run every time MSBuid and CC.Net is big pain. You can’t run MSTest on computer without VS on it (not 100 sure about 2010, but with 2008 it is so) not sure, sorry yes you can, from … Read more
You can create your own ExpectedException attribute where you can Assert the message of the Exception that was thrown. Code namespace TestProject { public sealed class MyExpectedException : ExpectedExceptionBaseAttribute { private Type _expectedExceptionType; private string _expectedExceptionMessage; public MyExpectedException(Type expectedExceptionType) { _expectedExceptionType = expectedExceptionType; _expectedExceptionMessage = string.Empty; } public MyExpectedException(Type expectedExceptionType, string expectedExceptionMessage) { _expectedExceptionType = … Read more
I was getting a similar issue running Xamarin.UITests and resolved it by installing the “NUnit 2 Test Adapter” Extension in Visual Studio. In Visual Studio 2017 you do this from Tools > > Extensions and Updates… > Online > Search “NUnit Adapter” > click the NUnit 2 Test Adapter then the Download button to install. … Read more
[TestMethod] Test1Row1 { Test1(1,4,5); } [TestMethod] Test1Row2 { Test1(1,7,8); } private Test1(int i, int j, int k) { //all code and assertions in here }
As others have pointed out, it’s best to stick with one assert in each test in order to avoid losing information – if the first assert fails, you don’t know whether the later ones would fail also. You have to fix the problem with less information – which might (probably will) be harder. A very … Read more
As I found out today, the static constructor CAN be called directly: from another Stackoverflow post The other answers are excellent, but if you need to force a class constructor to run without having a reference to the type (ie. reflection), you can use: Type type = …; System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle); I had to add this code … Read more