Test Project and Test Class: To Create a Test Project

The following activity will walk you through the process of creating and configuring a test project.

Story

Suppose that you have an extension library implemented in the PhoneRepairShop_Code.csproj Visual Studio project. You need to create a test project in which you will develop unit tests for graphs and graph extensions in this extension library. You will use the xUnit.net library and the Acumatica Unit Test Framework in the unit tests.

Process Overview

In Visual Studio, you will create a test project in the same solution with the extension library that implements the graphs and graph extensions being tested. You will add the required NuGet packages to the test project. You will also add the PX.Tests.Unit.dll library and other libraries from the MYOB Acumatica instance to the test project.

System Preparation

As a prerequisite, before you begin creating a test project, make sure that you have performed the Test Instance for Unit Testing: To Deploy an Instance activity.

Step 1: Creating a Test Project

To create the PhoneRepairShop_Code.Tests.csproj project, proceed as follows:

  1. Open the PhoneRepairShop_Code.sln file, which is located in the \App_Data\Projects\PhoneRepairShop subfolder of the SmartFix_T280 instance folder.
  2. In Visual Studio, in the Solution Explorer panel, right-click the PhoneRepairShop_Code solution.
  3. Select Add > New Project.
  4. Select the Class Library (.NET Framework) project template.
  5. Click Next.
  6. Enter the PhoneRepairShop_Code.Tests project name, leave the value in the Location box unchanged, and specify .NET Framework 4.8 in the Framework box.
  7. Click Create.
  8. Delete the Class1.cs item from the PhoneRepairShop_Code.Tests.csproj project. You will create the required C# classes later.

Step 2: Adding NuGet Packages

Do the following to add the necessary NuGet packages to the PhoneRepairShop_Code.Tests.csproj project:

  1. In the Solution Explorer panel of Visual Studio, right-click the PhoneRepairShop_Code.Tests project, and select Manage NuGet Packages.
  2. Install the following packages:
    • xunit (Version 2.4.2)
    • xunit.runner.visualstudio (Version 2.4.5)
    • System.Runtime.CompilerServices.Unsafe (Version 6.0.0)
    • Microsoft.Bcl.AsyncInterfaces (Version 8.0.0)
    • Moq (Version 4.18.0)

Step 3: Adding References to the Customization Code and MYOB Acumatica Libraries

To add references to the customization project and MYOB Acumatica libraries to the PhoneRepairShop_Code.Tests.csproj project, proceed as follows:

  1. Copy the PX.Tests.Unit.dll file from the UnitTesting subfolder of the MYOB Acumatica installation folder to any folder you choose.
  2. Right-click the References item of the PhoneRepairShop_Code.Tests project, and select Add Reference.
  3. On the Browse tab, click Browse.
  4. In the SmartFix_T280\Bin folder, select the following files:
    • PX.Common.dll
    • PX.Common.Std.dll (this library makes it possible to use graph views in the code)
    • PX.Data.BQL.Fluent.dll
    • PX.Data.dll
    • PX.Objects.dll (this library contains the implementation of the PX.Objects.IN.InventoryItem class)
  5. Select the PX.Tests.Unit.dll file in the folder where you have placed it.
  6. On the Projects tab, select the PhoneRepairShop_Code project.
  7. Click OK.