Skip to main content
Solved

bypass a prefetchable in unit testing


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.

Best answer by Naveen Boga

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!!

View original
Did this topic help you find an answer to your question?

2 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3377 replies
  • Answer
  • March 21, 2021

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!!


  • Author
  • Freshman I
  • 4 replies
  • March 21, 2021
Naveen B wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings