Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[Transformations][TESTS] Transformation tests doc update (#36685)

Vladislav Golubev6b50ffe624ac
diff --git a/.claude/skills/ov-transformation-tests/SKILL.md b/.claude/skills/ov-transformation-tests/SKILL.md
index a5626a68b2b..06f0c4e7bf7 100644
--- a/.claude/skills/ov-transformation-tests/SKILL.md
+++ b/.claude/skills/ov-transformation-tests/SKILL.md
@@ -6,6 +6,6 @@ description: >
(MatcherPass, ModelPass), or to modernize legacy transformation tests.
---
-1. Read `src/common/transformations/docs/writing_tests.md` — it covers test location, build target, fixture setup, FunctionsComparator flags, node builders, model builder helpers, parametrized and negative test patterns, and what NOT to do.
+1. Read [src/common/transformations/docs/writing_tests.md](../../../src/common/transformations/docs/writing_tests.md) — it covers test location, build target, fixture setup, FunctionsComparator flags, node builders, model builder helpers, parametrized and negative test patterns, and what NOT to do.
2. Write or modify the test file(s) following the patterns in that guide.
3. Build and run the tests to ensure all tests pass.
diff --git a/src/common/transformations/docs/writing_tests.md b/src/common/transformations/docs/writing_tests.md
index d82780d178c..530dbf18495 100644
--- a/src/common/transformations/docs/writing_tests.md
+++ b/src/common/transformations/docs/writing_tests.md
@@ -4,17 +4,20 @@
- [Test location and build target](#test-location-and-build-target)
- [Quick checklist](#quick-checklist)
+- [Test naming conventions](#test-naming-conventions)
- [Test class setup](#test-class-setup)
+- [Fixture utilities](#fixture-utilities)
- [FunctionsComparator flags](#functionscomparator-flags)
- [Node builders](#node-builders)
- [Model builder helpers](#model-builder-helpers)
- [Parametrized tests](#parametrized-tests)
- [Negative tests (transformation must NOT fire)](#negative-tests-transformation-must-not-fire)
+- [Migrating from legacy patterns](#migrating-from-legacy-patterns)
- [What NOT to do](#what-not-to-do)
## Test location and build target
-Test files live in `src/common/transformations/tests/` with subdirectories by category (e.g., `common_optimizations/`, `utils/`). Build and run all transformation tests with:
+Test files live in [src/common/transformations/tests/](../tests/) with subdirectories by category (e.g., `common_optimizations/`, `utils/`). Build and run all transformation tests with:
```bash
cmake --build build --target ov_transformations_tests -j$(nproc)
@@ -35,6 +38,15 @@ Or run a single test:
5. Consider using `node_builders/` helpers instead of directly instantiating ops when a builder exists and improves test readability
6. Avoid building `model_ref` when the transformation does not modify the `model`, since `model_ref` is initialized as a clone of `model` by default
+## Test naming conventions
+
+Test names should describe **what is being tested**, not just assign a number:
+
+- Bad: `ConvertMatMulToFCTest1`, `ConvertMatMulToFCTest2`, `ConvertMatMulToFCTest3`
+- Good: `BothParamsNotConverted`, `TypeRelaxedU8I8`, `DecompressF16Weights_TransposeA`
+
+For parametrized tests, provide a `getTestCaseName` that produces readable suffixes (e.g., `3d_static_2x2`, `4d_dynamic_10x5`).
+
## Test class setup
```cpp
@@ -78,6 +90,18 @@ TEST_F(MyTransformTests, MyTransformName_SomeVariant) {
**Never** manually create a `pass::Manager`, call `check_rt_info`, or call `compare_functions` — those are handled by the fixture.
+## Fixture utilities
+
+`TransformationTestsF` provides several helper methods beyond `manager` and `comparator`:
+
+| Method | When to use |
+|--------|-------------|
+| `disable_rt_info_check()` | Transformation creates new nodes that don't carry `rt_info` from originals (e.g., fusions that build entirely new subgraphs). Call in the test body before `TearDown`. |
+| `disable_result_friendly_names_check()` | Transformation legitimately changes Result friendly names (rare). |
+| `enable_soft_names_comparison()` | Compare friendly names by substring match instead of exact equality. Useful when the transformation appends suffixes. |
+
+**Prefer fixing the transformation** over using these workarounds. If a transformation drops friendly names or `rt_info` that it should preserve, fix the transformation code (e.g., add `new_node->set_friendly_name(old_node->get_friendly_name())` or copy `rt_info`). Only use `disable_*` when the transformation's behavior is intentional.
+
## FunctionsComparator flags
`TransformationTestsF` initialises the comparator with `no_default()` and then explicitly enables `NODES | PRECISIONS | RUNTIME_KEYS | SUBGRAPH_DESCRIPTORS`.
@@ -112,7 +136,7 @@ Do **not** explicitly enable flags already on by default in `TransformationTests
## Node builders
Use `node_builders/` helpers instead of constructing ops directly when a builder exists and improves test readability.
-Headers live in `src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/`.
+Headers live in [src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/](../../../tests/test_utils/common_test_utils/include/common_test_utils/node_builders/).
Import example:
```cpp
@@ -209,13 +233,52 @@ When the transformation should leave the `model` unchanged, leave `model_ref` as
TEST_F(TransformationTestsF, MyTransform_Negative_SomeCondition) {
model = buildOriginal(…);
manager.register_pass<ov::pass::MyTransformation>();
- // model_ref intentionally omitted
}
```
+## Migrating from legacy patterns
+
+### `TYPED_TEST_P` with manual Manager
+
+Legacy pattern:
+```cpp
+template <class T>
+class MyTest : public testing::Test {};
+
+TYPED_TEST_P(MyTest, Applied) {
+ ov::pass::Manager m;
+ m.register_pass<SomePass<TypeParam>>();
+ m.run_passes(model);
+ auto res = compare_functions(model, model_ref);
+ ASSERT_TRUE(res.first);
+}
+```
+
+Migration: replace with runtime parametrization using a struct with factory lambdas:
+```cpp
+struct MyTestParams {
+ std::string name;
+ std::function<std::shared_ptr<ov::Node>(args...)> makeOp;
+ std::function<void(ov::pass::Manager&)> registerPass;
+};
+
+class MyTest : public TransformationTestsF,
+ public WithParamInterface<MyTestParams> {};
+
+TEST_P(MyTest, CompareWithRef) {
+ const auto& p = GetParam();
+ // build model using p.makeOp
+ p.registerPass(manager);
+}
+```
+
+This preserves type coverage while gaining `TransformationTestsF` benefits.
+
## What NOT to do
- Do **not** inherit from plain `TransformationTests` / `ov::test::TestsCommon`
- Do **not** manually instantiate `pass::Manager` or call `manager.run_passes(model)`
- Do **not** call `check_rt_info(f)` or the deprecated `compare_functions(f, f_ref, …)`
- Do **not** add flags already on by default in `TransformationTestsF` (`NODES`, `PRECISIONS`, `RUNTIME_KEYS`, `SUBGRAPH_DESCRIPTORS`)
+- Do **not** use numbered test names (`Test1`, `Test2`) — use descriptive names that explain the scenario
+- Do **not** add comments like `// model_ref intentionally omitted` — the convention is self-documenting