Implementing testplan Setup and Teardown

Hello again,

I am looking to implement Setup and Tear-down of a test plan which is something very common in all kinds of testing.
Setup and tear-down are essentially parts of the testplan that do not affect the results. In the case of tear-down, it must be run whether the test was aborted, terminated by error or finished as pass or fail.

In my case i want to be setting up and turning off the Power supply. At the beginning and end of testplan

I was surprised to see that Opentap doesn’t support that and I am trying to think of a way to implement that myself.

I tried creating a teststep with override method Run empty and implement the pre-plan /post-plan methods that will execute child steps only there.

However that is not working, I believe opentap is only looking to execute the post and pre plan of the child steps since they are called from that point. And since those methods are not overridden in child steps they just throw a null exemption.

i know that each step has its own pre and post-plan that you can individually execute setup and tear-down but this is a different concept of what i am looking to implement.

Hi connospp,

It sounds like OpenTAP already supports your use-case. What you need to to is to implement an Instrument for your power supply. OpenTAP will call the Open method on any configured instrument (or resource) before the test plan starts, and Close after the test plan stops (whether it was aborted or completed normally).

I don’t think you actually need SetUp / TearDown in this instance, but it can be achieved by implementing the ITestPlanRunMonitor interface. The methods EnterTestPlanRun and ExitTestPlanRun will be executed immediately before and after a test plan. I would however advise against it because OpenTAP knows how to handle IResource / IInstrument implementations properly.

For example if you implement

public class MyPowerSupply : Instrument {
  // implementation
public class MyTestStep : TestStep {
  public MyPowerSupply PSU { get; set; }

then the test plan GUI will let you easily choose between all configured instances of MyPowerSupply in your current bench settings, whereas you would need to create a hardcoded solution for your particular instrument in both the PrePlanRun / PostPlanRun and ITestPlanRunMonitor scenarios.

I hope this makes sense. If not, there are some example implementations of instruments and DUTs in the SDK Examples

1 Like

Thank you @alexander.larsen

Will look into the solution. Seems that it is what I look for