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:
- Open the PhoneRepairShop_Code.sln file, which is located in the \App_Data\Projects\PhoneRepairShop subfolder of the SmartFix_T280 instance folder.
- In Visual Studio, in the Solution Explorer panel,
right-click the
PhoneRepairShop_Code
solution. - Select .
- Select the Class Library (.NET Framework) project template.
- Click Next.
- 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.
- Click Create.
- 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:
- In the Solution Explorer panel of Visual Studio,
right-click the
PhoneRepairShop_Code.Tests
project, and select Manage NuGet Packages. - 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:
- Copy the PX.Tests.Unit.dll file from the UnitTesting subfolder of the MYOB Acumatica installation folder to any folder you choose.
- Right-click the References item of the
PhoneRepairShop_Code.Tests
project, and select Add Reference. - On the Browse tab, click Browse.
- 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)
- Select the PX.Tests.Unit.dll file in the folder where you have placed it.
- On the Projects tab, select the
PhoneRepairShop_Code
project. - Click OK.