# Implementing testplan Setup and Teardown

**URL:** <https://forum.opentap.io/t/implementing-testplan-setup-and-teardown/790>\
**Category:** Technical\
**Created:** [August 2, 2022, 8:44am UTC](https://forum.opentap.io/t/implementing-testplan-setup-and-teardown/790 "2022-08-02T08:44:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![alexander.larsen](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@alexander.larsen](https://forum.opentap.io/u/alexander.larsen)\
**Post date:** [August 2, 2022, 1:19pm UTC](https://forum.opentap.io/t/implementing-testplan-setup-and-teardown/790/2 "2022-08-02T13:19:36Z")

</div>

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

```csharp
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](https://github.com/opentap/opentap/tree/main/sdk/Examples/PluginDevelopment/InstrumentsAndDuts)

---

_[View the full topic](https://forum.opentap.io/t/implementing-testplan-setup-and-teardown/790)._
