You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contributing/topics/reference-acceptance-testing.md
+58-2Lines changed: 58 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,62 @@ As a general rule, the more complex the resource the more tests there are - for
18
18
19
19
See [Running the Tests](running-the-tests.md).
20
20
21
+
### PreCheck Helpers
22
+
23
+
Acceptance tests frequently require additional prerequisites beyond the standard Azure credentials and test locations (for example, access to a real DNS zone, an existing Key Vault/certificate, or other shared infrastructure).
24
+
25
+
To keep tests reliable (and to avoid creating resources that will inevitably fail), use a **pre-check** to either:
26
+
27
+
***Skip** a test when optional external prerequisites are not available (e.g. an environment variable pointing to shared infrastructure is not set).
28
+
***Fail fast** only when the prerequisite is considered mandatory for all acceptance tests in the suite.
29
+
30
+
#### Global pre-check (mandatory)
31
+
32
+
The acceptance test framework already includes a global pre-check (`acceptance.PreCheck(t)`) which validates the required Azure authentication and test location environment variables.
33
+
34
+
This is intended for prerequisites that are required for *all* acceptance tests.
For additional, test-specific prerequisites, the common convention in this repository is to implement a receiver method named `preCheck(t *testing.T)` on the test struct (for example `type ExampleResource struct {}`) and call it at the start of each `TestAcc...` that requires it.
39
+
40
+
When the prerequisites are not met, these pre-checks should typically call `t.Skip(...)` / `t.Skipf(...)` (rather than `t.Fatalf(...)`) so that:
41
+
42
+
* contributors without the optional infrastructure can still run unrelated tests successfully;
43
+
* CI or scheduled runs can provide the prerequisites and run the full suite.
t.Skip("Skipping as ARM_TEST_SOME_PREREQ is not set")
69
+
}
70
+
}
71
+
```
72
+
73
+
#### Where to put `preCheck`
74
+
75
+
Go does not require a specific function order, but for readability it is recommended to place `preCheck` close to the tests that call it (commonly after the `TestAcc...` functions and before the `Exists`/`Destroy` methods), following the pattern used throughout `internal/services/*/*_test.go`.
76
+
21
77
### Test Package
22
78
23
79
While tests reside in the same folder as resource and data source .go files, they need to be in a separate test package to prevent circular references. i.e. for the file `./internal/services/aab2c/aadb2c_directory_data_source_test.go` the package should be:
0 commit comments