Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.46 KB

MachineNameSpecificTest.md

File metadata and controls

37 lines (27 loc) · 1.46 KB

How to run tests only on specific machines

Contents

Introduction

In some cases, you may want tests to run only on specific machines. This can be achieved by using NamedEnvironment at the beginning of your tests.

Using NamedEnvironment

You can use the NamedEnvironment class in combination with isCurrentEnvironmentValidFor to achieve this.

Here is an example that uses the NamedEnvironment class to run tests only on a specific machine. It checks if the current machine's name matches the specified name (e.g., ".lars-mbp-14"), and if not, the test is skipped. The actual test code should be placed after this condition.

try (NamedEnvironment namedEnvironment = NamerFactory.asMachineNameSpecificTest())
{
  if (!namedEnvironment.isCurrentEnvironmentValidFor(".lars-mbp-14"))
  { return; }
  // the rest of your test...

snippet source | anchor

please note: this will also append the machine name to the ApprovalTest so that each specific machine gets its own .approved file.