Ensuring unit test data stays accurate

Say I have a method that expects data to be in some form to perform accurately. In the actual service/application flow, that data is formed upstream in other methods or services. How can I ensure the unit tests for the method in question act on accurate data? If I create mock data, then the upstream part that is responsible for creating that data in the flow of the application changes, then the unit test data is now inaccurate in relation to the whole application or service. Despite the method under test is still acting on the old data, so now it’s obsolete and broken but the tests are still passing since the test data is in the form it’s expecting. I have created service wide test data that all tests on that service use, to try to keep it inline with what’s accurate to the service. Is this a worry of integration tests?

Jan 18, 2025 - 19:28
Ensuring unit test data stays accurate

Say I have a method that expects data to be in some form to perform accurately. In the actual service/application flow, that data is formed upstream in other methods or services. How can I ensure the unit tests for the method in question act on accurate data? If I create mock data, then the upstream part that is responsible for creating that data in the flow of the application changes, then the unit test data is now inaccurate in relation to the whole application or service. Despite the method under test is still acting on the old data, so now it’s obsolete and broken but the tests are still passing since the test data is in the form it’s expecting.

I have created service wide test data that all tests on that service use, to try to keep it inline with what’s accurate to the service.

Is this a worry of integration tests?