unit testing in acumatica erp

21
Unit Testing in Acumatica ERP Dmitrii Naumov Solution Architect [email protected]

Upload: others

Post on 26-Oct-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Unit Testing in Acumatica ERP

Unit Testing in

Acumatica ERP

Dmitrii NaumovSolution Architect

[email protected]

Page 2: Unit Testing in Acumatica ERP

2

Agenda

• Introduction

• Acumatica Unit Testing Framework Overview

• Mocking Data for Unit Testing

• Demo

• Summary

Page 3: Unit Testing in Acumatica ERP

3

Feedback Time / Cost of the Bugfix

Types of Software Testing

UAT

Performance

Testing

System Testing

Integration Testing

Unit Testing

Static Code Analysis

Page 4: Unit Testing in Acumatica ERP

4

Types of Testing in Acumatica

UAT

Performance

Testing

System Testing

Integration Testing

Unit Testing

Static Code Analysis

Manual Testing

Test SDK

Unit Tests Framework

Acuminator

Page 5: Unit Testing in Acumatica ERP

5

Unit Testing

Pros:

• Fast execution

• Fast development

• Tests exact function of the system

Cons:

• Does not test real user scenarios

• Requires a specific architecture

Page 6: Unit Testing in Acumatica ERP

6

Acumatica Unit Tests Framework Overview

Page 7: Unit Testing in Acumatica ERP

7

Unit Tests Framework Overview

• Tests PXGraph behavior

• Code is very similar to our Acumatica Framework code

• Selection of records from the database is easy to mock-up

• Based on Xunit (popular .Net Unit tests framework)

Page 8: Unit Testing in Acumatica ERP

8

public void Test_Calculation_UnitPrice()

{

// Preparing the data

SOOrderEntry graph = PrepareGraph();

// Perfom an action

var orderLine = graph.Transactions.Insert();

orderLine.InventoryID = stockItem.InventoryID;

orderLine.Qty = 1;

orderLine = graph.Transactions.Update(orderLine);

// Check the result

Assert.Equal("LBS", orderLine.UOM);

Assert.InRange(orderLine.CuryUnitPrice.Value, 227m, 228m);

}

Example of Test

Page 9: Unit Testing in Acumatica ERP

9

public void Test_Calculation_UnitPrice()

{

// Preparing the data

SOOrderEntry graph = PrepareGraph();

// Perfom an action

var orderLine = graph.Transactions.Insert();

orderLine.InventoryID = stockItem.InventoryID;

orderLine.Qty = 1;

orderLine = graph.Transactions.Update(orderLine);

// Check the result

Assert.Equal("LBS", orderLine.UOM);

Assert.InRange(orderLine.CuryUnitPrice.Value, 227m, 228m);

}

Example of Test

Page 10: Unit Testing in Acumatica ERP

10

public void Test_Calculation_UnitPrice()

{

// Preparing the data

SOOrderEntry graph = PrepareGraph();

// Perfom an action

var orderLine = graph.Transactions.Insert();

orderLine.InventoryID = stockItem.InventoryID;

orderLine.Qty = 1;

orderLine = graph.Transactions.Update(orderLine);

// Check the result

Assert.Equal("LBS", orderLine.UOM);

Assert.InRange(orderLine.CuryUnitPrice.Value, 227m, 228m);

}

Example of Test

Page 11: Unit Testing in Acumatica ERP

11

public void Test_Calculation_UnitPrice()

{

// Preparing the data

SOOrderEntry graph = PrepareGraph();

// Perfom an action

var orderLine = graph.Transactions.Insert();

orderLine.InventoryID = stockItem.InventoryID;

orderLine.Qty = 1;

orderLine = graph.Transactions.Update(orderLine);

// Check the result

Assert.Equal("LBS", orderLine.UOM);

Assert.InRange(orderLine.CuryUnitPrice.Value, 227m, 228m);

}

Example of Test

Page 12: Unit Testing in Acumatica ERP

12

Mocking Data and Dependencies

PXGraph

PXSelect

Test

Sample

Data in

PXCache

PXSetupService

Dependency

Mock

Setup

Mock

Services

Page 13: Unit Testing in Acumatica ERP

13

Example of Unit Test

Page 14: Unit Testing in Acumatica ERP

14

Example Test

1. Add Inventory Item with

▪ Base Unit of Measure - KG

▪ Sales Unit of Measure – LBS

▪ Price – 500$ for KG

2. Create a Sales Order with 1 Line

3. Check that Unit of Measure in line is Sales Unit (LBS)

4. Check that price has been recalculated properly from Price for KG to Price for LBS

Page 15: Unit Testing in Acumatica ERP

15

Mocking Data for Unit Tests

Page 16: Unit Testing in Acumatica ERP

16

Layers

GL Configuration

CA Configuration

AR Configuration AP Configuration

SO Configuration PO Configuration

IN Configuration

Page 17: Unit Testing in Acumatica ERP

17

Switch to Visual Studio for demo here

Page 18: Unit Testing in Acumatica ERP

18

Summary

• All types of tests are important

• Unit tests bring a lot of value

• It works as documentation of your code

• It helps reduces the feedback cycle about a bug with the product

• It’s beneficial from the start

• It’s easy to start with Acumatica Unit Tests Framework

• Code is similar to regular Acumatica Framework code

• Easy to mock data

• Easy to reuse data mocking

Page 19: Unit Testing in Acumatica ERP

19

Call to Action

• Check out the GitHib repo with Unit test examples

https://github.com/Acumatica/UnitTestsDemo

• Email ([email protected]) if you have any questions or have ideas to

improve the unit tests.

• Get Involved in our Developer Community!

• Join us on stackoverflow: https://stackoverflow.com/questions/tagged/acumatica/

• Check https://www.acumatica.com/developers/ regularly!

• Read our developer blogs: https://www.acumatica.com/blog/category/developers/

• Attend Summit 2021 | Hackathon 2021: https://summit.acumatica.com/

Page 20: Unit Testing in Acumatica ERP

20

Q&A

Page 21: Unit Testing in Acumatica ERP

Thank You!

Dmitrii NaumovSolutions Architect

[email protected]