Skip to content

Detect fields initialized in (OneTime)Setup being overwritten later. #930

@manfred-brands

Description

@manfred-brands

If fields or properties are overwritten this could lead to hard to find test errors where a test runs fine if run on its own, but not when a whole fixture is tested.

Fields initialized in SetUp methods should be considered read-only.
In general, individual test method should never initialize fields, but only locals.
The exception would be where the tests have an Order attribute applied and the later test uses the value of the earlier tests.

We need to detect:

  • When a SetUp method initializes a field already initialized in a OneTimeSetUp method
  • When any other method assigns a value to a field already initialized in a OneTimeSetUp or SetUp method

This came up in #904 but the situation is not only for disposable fields.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions