Unit testing private methods in C#

You can use the PrivateObject class: Class target = new Class(); PrivateObject obj = new PrivateObject(target); var retVal = obj.Invoke(“PrivateMethod”); Assert.AreEqual(expectedVal, retVal); Note: PrivateObject and PrivateType are not available for projects targeting netcoreapp2.0 – GitHub Issue 366

NUnit vs. MbUnit vs. MSTest vs. xUnit.net [closed]

I know this is an old thread, but I thought I’d post a vote for xUnit.NET. While most of the other testing frameworks mentioned are all pretty much the same, xUnit.NET has taken a pretty unique, modern, and flexible approach to unit testing. It changes terminology, so you no longer define TestFixtures and Tests…you specify … Read more

How do I use Assert to verify that an exception has been thrown?

For “Visual Studio Team Test” it appears you apply the ExpectedException attribute to the test’s method. Sample from the documentation here: A Unit Testing Walkthrough with Visual Studio Team Test [TestMethod] [ExpectedException(typeof(ArgumentException), “A userId of null was inappropriately allowed.”)] public void NullUserIdInConstructor() { LogonInfo logonInfo = new LogonInfo(null, “P@ss0word”); }

techhipbettruvabetnorabahisbahis forumuedueduedusedusedusedueduedueduedu