Solved

bypass a prefetchable in unit testing

  • 20 March 2021
  • 2 replies
  • 53 views

on my constructor, I put a checker if this feature is available or not, using prefetchable.
 

public ModelTypeMaint()
{
Helpers.PreferenceHelper.CheckFeatures();
}

 

Now, I have tried to run a unit test on this particular graph, unfortunately even though I’ve implemented a mock setup, It still reads the Prefetchable checker.

How do I bypass the prefetchable on the constructor?

Unit Test Code

private ModelTypeMaint PrepareGraph()
{
SetupEnableDisable<ModelTypeMaint>();
var graph = PXGraph.CreateInstance<ModelTypeMaint>();
return graph;
}

[Fact]
public void Test_Description_ValidLength()
{
ModelTypeMaint graph = PrepareGraph();

ModelType type = (ModelType)graph.Caches[typeof(ModelType)].Insert(new ModelType
{
ModelCD = "UT00001",
Description = "Model Type: UNIT 00001"
});

Assert.InRange(type.Description.Length, 5, 255);
}

 

Thank you.

icon

Best answer by Naveen Boga 21 March 2021, 11:45

View original

2 replies

Userlevel 7
Badge +17

Hi @igalm15, I don’t think we can bypass the constructor code.

If this is your custom Graph file, (ModelTypeMaint), just simply comment that particular code and perform the unit testing.

You can also do this by having a setup screen with a checkbox field “Check Features”, based on this flag configuration, it can skip the constructor code.

 

Hope this helps!!

Hi @igalm15, I don’t think we can bypass the constructor code.

If this is your custom Graph file, (ModelTypeMaint), just simply comment that particular code and perform the unit testing.

You can also do this by having a setup screen with a checkbox field “Check Features”, based on this flag configuration, it can skip the constructor code.

 

Hope this helps!!

 

Hello @Naveen B , Thank you for your input. I was able to do the testing by commenting the checker on my constructor. But I’ll try your second suggestion, I’ll also make a test that will check the Check Feature setup should be checked. :) 

Again, thank you.

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