Solved

In Unit Test Framework can we fetch values from DB or using PXSelect Query for Table

  • 1 September 2022
  • 3 replies
  • 67 views

Userlevel 4
Badge +1

Hi,
In Unit Test Framework can we fetch values from DB or using PXSelect Query for Table.

I am getting null object when i use PXSelect in unit test framework

Thanks.

icon

Best answer by Dmitrii Naumov 2 September 2022, 17:05

View original

3 replies

Userlevel 7
Badge +5

@girik06 The idea of Unit tests is that you can run them without a need to setup a DB. Setting up a DB is tedious and a source of errors if data in the DB is not matching. 

 

Instead, in the unit tests you should prepare all the data you need in the code of the test itself. 

 

E.g. see here:

https://github.com/Acumatica/UnitTestExamples/blob/master/UnitTestsDemo/Tests/CATransferTest.cs

 

We need to have a cashaccount for this test. So we just insert it in the cache:

graph.Caches[typeof(CashAccount)].Insert(
new CashAccount {
CashAccountCD = "102000",
CuryID = "USD"
});

After that we can use PXSelect<CashAccount>.Select(graph) and it will return the inserted cashaccount form the cache.

Userlevel 4
Badge +1

Hi Dmitrii @Dmitrii Naumov - I would like to confirm if this kind of test can be performed in Unit Test Framework

Simple use case:

e.g. Can I pass AACUSTOMER as Input in Sales Order, extract the Payment Terms from DB and for the given Order Type only Prepayment is allowed and hence if any other Payment Term is defaulted then I would like to Fail the test

 

Use Case is we will pass Part of the Input but we would like to extract from DB based on the 1st set of Input and compare for the Results

Userlevel 7
Badge +5

@girik06  You’ll need to setup the data in the graph cache before executing the test.

 

E,g, you’ll need to insert needed OrderType rows and PaymentTerms rows in the respective caches of SOOrderEntry graph and then you’ll be able to perform the test.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved