ttc-cases / pydevx-lindjacob

1 stars 0 forks source link

Extend or exemplify the unit test with support for mockups #15

Closed lindjacob closed 2 weeks ago

lindjacob commented 2 months ago

Here's a piece of wisdom that a GPT came up with. I asked it the following prompt:

What are the benefits of using mocks in unit tests.

Here are a few arguments:

Mocks allow testers to simulate the behavior of real objects in a controlled way, enabling tests to focus on the logic under test without relying on the actual implementation details of dependencies. Here are some key benefits of using mocks:

  1. Isolation: Mocks help in isolating the component under test from its dependencies. This ensures that the test only fails because of issues in the component being tested, not because of problems in its dependencies.

  2. Controlled Environment: Mocks allow you to control the behavior of dependencies, such as returning specific values or throwing exceptions. This makes tests predictable and repeatable.

  3. Speed: Tests that use mocks can often run faster since they don't require the actual components to be executed. This is particularly beneficial in integration tests where setting up the entire system can be time-consuming.

  4. Flexibility: Mocks can simulate various scenarios, such as different responses from a service or database, allowing you to test how your code handles these situations.

Add a unit test to the project that uses mocks

Commit your unit test mock to the repository. In the comments of this issue put a few words on what goes on in the using test, why did you go with exactly this example.

Are mocks relevant in something as simple at this code base? Argue Why? or Why not?

lindjacob commented 2 weeks ago

I have mocked the hand function. It works by intercepting the return value and substituting it with a constant that I have decided. I tested the hand class as it was the only thing object with a return value that we can test with a mock.

No, mocks are not relevant for this code, because there is nothing to really isolate. When using mocks, we are isolating a logic from its dependencies that would otherwise slow down or maybe "break" our tests without anything being wrong with our code. Using mock tests generally lowers our confidence in our tests as anything mocked is not actually testing a real scenario. Integration tests would be better here.