Skip to main content

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.

@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.CachesCtypeof(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.


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


@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