Overriding PrePlanRun() and PostPlanRun()

I would like to override PrePlanRun() and PostPlanRun() in my TestStep derived class so that base method wouldn’t be used and respective methods of child steps wouldn’t be called. I declared two methods that just log a message, e.g.:

        public override void PostPlanRun()
        {
            Log.Warning("Executing PostPlanRun");
        }

I can see the messages coming from the overrides but I also see that PrePlanRun() and PostPlanRun() methods of the child steps are still called. Is there a way to prevent that?

1 Like

For that, I believe you want to use the new modifier instead of override:

        new public void PostPlanRun()
        {
            Log.Warning("Executing PostPlanRun");
        }

Override extends the base implementation, new hides it:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/new-modifier

1 Like

@brennen_direnzo Oh, shame on me haha. Thanks for the link, refreshed my knowledge about the other keywords as well.

That said, if I use new it seems my implementation is not called at all whereas the ‘default’ one is still being called. Is there something else I don’t fully understand?

It’s possible it is forcing to use the default, however, that default should be empty, so what is it you are trying to ignore?

As mentioned, I don’t want PrePlanRun() and PostPlanRun() methods of my step’s child steps to be called. But according to the log they are being called.

Is it that the ChildSteps can exist at the top level of the Test Plan/Non-child steps and in that case you would want PrePlanRun and PostPlanRun to be called, but when used as Child steps you do not want those methods to be called?

Not exactly. I want any step that is placed under the parent step I’m working on to skip PrePlanRun() and PostPlanRun().

I don’t think that is actually possible today, although PrePlanRun and PostPlanRun default to not doing anything. Are you looking at this from a performance perspective or to actually avoid calling something that has been implemented in some cases?

It’s not related to performance, I just want to avoid calling something that has been implemented.

1 Like

I think the only way to do this today would actually be in the PrePlanRun and PostPlanRun methods of the child steps.

I was confusing this earlier in that new (even if it worked) would only affect the Parent step anyway. So, I think the way to do this would be in the Child Step Pre/PostPlanRun methods check this.Parent and either execute or skip based on that type.

I see. Implementing that in child steps would make child and parent steps coupled which I would love to avoid…

1 Like

Yeah makes sense. Can you submit a feature request and summarize the need? I don’t have a great thought on how to make it work, but maybe our R&D will.