Skip to main content
Clarified first sentence
Source Link
Greg Burghardt
  • 46.1k
  • 8
  • 87
  • 150

Rather than testing the output of someTests are not limited to verifying application logic executed in memory. If all your test does is verify calls to mocks, then you wantare verifying implementation. You are right to verifyquestion the outputvalue of making that call tosuch tests for the very reasons you mention in your question. This happens at the boundaries between your application and some other system, like a database or web API. There tends to be very little logic to test. That doesn't mean tests are not valuable, file systemthough.

Instead of using mocks, oruse the real thing — an actual database. This is a perfectly valid technique for testing infrastructure modules or web service. While testing terminology isn't standardized, you'll hear many people call this a form of integration testing. You are still testing the output, but not the output of a function in your program. You are testing the output generated by two or more systems working together.

These kinds of tests run slower than what you classify as a unit test. That's ok. Just don't run these tests as often. Be careful when running integration tests against a shared resource, so one test does not interfere with the output of another. File paths, database connection strings and URLs to web service should be parameterized so you can run tests against a local database, temp files, or a local copy of a web service.

That doesn't mean you cannot run tests against a shared resource. This might be desirable in a CI/CD build, but this becomes a matter of configuration and deployment.

At some point there is no benefit to mocking function calls. You need to test the real thing.

Rather than testing the output of some logic executed in memory, you want to verify the output of making that call to the web API, file system, or database. This is a perfectly valid technique for testing infrastructure modules. While testing terminology isn't standardized, you'll hear many people call this a form of integration testing.

These kinds of tests run slower than what you classify as a unit test. That's ok. Just don't run these tests as often. Be careful when running integration tests against a shared resource, so one test does not interfere with the output of another. File paths, database connection strings and URLs to web service should be parameterized so you can run tests against a local database, temp files, or a local copy of a web service.

That doesn't mean you cannot run tests against a shared resource. This might be desirable in a CI/CD build, but this becomes a matter of configuration and deployment.

At some point there is no benefit to mocking function calls. You need to test the real thing.

Tests are not limited to verifying application logic. If all your test does is verify calls to mocks, then you are verifying implementation. You are right to question the value of such tests for the very reasons you mention in your question. This happens at the boundaries between your application and some other system, like a database or web API. There tends to be very little logic to test. That doesn't mean tests are not valuable, though.

Instead of using mocks, use the real thing — an actual database or web service. While testing terminology isn't standardized, you'll hear many people call this a form of integration testing. You are still testing the output, but not the output of a function in your program. You are testing the output generated by two or more systems working together.

These kinds of tests run slower than what you classify as a unit test. That's ok. Just don't run these tests as often. Be careful when running integration tests against a shared resource, so one test does not interfere with the output of another. File paths, database connection strings and URLs to web service should be parameterized so you can run tests against a local database, temp files, or a local copy of a web service.

That doesn't mean you cannot run tests against a shared resource. This might be desirable in a CI/CD build, but this becomes a matter of configuration and deployment.

At some point there is no benefit to mocking function calls. You need to test the real thing.

Source Link
Greg Burghardt
  • 46.1k
  • 8
  • 87
  • 150

Rather than testing the output of some logic executed in memory, you want to verify the output of making that call to the web API, file system, or database. This is a perfectly valid technique for testing infrastructure modules. While testing terminology isn't standardized, you'll hear many people call this a form of integration testing.

These kinds of tests run slower than what you classify as a unit test. That's ok. Just don't run these tests as often. Be careful when running integration tests against a shared resource, so one test does not interfere with the output of another. File paths, database connection strings and URLs to web service should be parameterized so you can run tests against a local database, temp files, or a local copy of a web service.

That doesn't mean you cannot run tests against a shared resource. This might be desirable in a CI/CD build, but this becomes a matter of configuration and deployment.

At some point there is no benefit to mocking function calls. You need to test the real thing.