Posts

Showing posts with the label xUnit

Donate

How To Prioritize xUnit Test Methods Using TestPriority Attributes and ITestCaseOrderer Interface

Image
Hello, A requirement for a project wherein we want to prioritize tests given that a certain algorithm depends on the execution of another one, we need to create tests priorities so that test methods are executed in a sequential order. After doing some research, I found an article here that demonstrates on how to control the execution order of test methods. Given the sample code below in a console application, I would like to set a priority for each method using the MDAS (Multiplication->Division->Addition->Subtraction) rule using the concepts from that article. public class MathOperations { public double Addition( double a, double b) { return a + b; } public double Subtraction( double a, double b) { return a - b; } public double Multiplication( double a, double b) { var result = a * b; return result; } public double Division( double a, double b) { var result = a / b; return result; } } The methodology that I ...

Mocking Methods With Ref Arguments Using Moq Framework In C#

Image
Hello, Here's a straightforward post on how to mock methods with arguments that are passed by reference using the Moq framework. First, we need to create a C# Class Library and Xunit projects in Visual Studio. Create two folders in the class libary project specifically Infrastructure and Models. The structure of the application resembles the image below. Add a class to hold a person's information Person.cs inside the models folder with properties such as SocialSecurityID, FirstName and etc. Only the StatusUpdate property is used in the test project. public class Person { public int SocialSecurityID { get ; set ; } public string FirstName { get ; set ; } public string MiddleName { get ; set ; } public string LastName { get ; set ; } public string StatusUpdate { get ; set ; } public Person() { SocialSecurityID = 0; FirstName = string .Empty; MiddleName = string .Empty; LastName = string .E...

Donate