Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #573

Open
Mirko-von-Leipzig opened this issue Dec 10, 2024 · 0 comments
Open

Refactor tests #573

Mirko-von-Leipzig opened this issue Dec 10, 2024 · 0 comments

Comments

@Mirko-von-Leipzig
Copy link
Contributor

Mirko-von-Leipzig commented Dec 10, 2024

As noted in PR #571, our usage of mocks in testing is somewhat brittle.

We should do a pass over all tests and ensure that we are actually testing the unit we think we are.

As an example, a lot of the block witness/prover tests here are actually testing test setup code that is not directly used by production code.

Mocks (in this context) are generally used to represent things that are painful to instantiate or setup e.g. database or a network connection. However usually in the long run these mocks quickly drift apart from the real thing. An indicator that we're doing the wrong thing is if we transform something into a trait purely so we can mock it during tests. This should be the last resort and must be strongly motivated (imo).

Some (better) alternatives:

  • Improve the underlying type by creating builders or making it easy to generate realistic input data. This is often the root friction causing us to reach for abstractable traits. Being able to actually generate real data trivially will pay dividends in the long run.
  • Separate the input source from the functionality you want to test. Separate of fn(InputSource) -> Output into fn(InputSource) -> Input and fn(Input) -> Output. The latter is usually much easier to test and generate input data for.
@Mirko-von-Leipzig Mirko-von-Leipzig changed the title Remove mocks from tests Refactor tests Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant