Câu hỏi phỏng vấn Software Testing
Câu hỏi

What's the difference between ...

Câu trả lời

In software testing, "faking," "mocking," and "stubbing" are techniques used to create test doubles, which are objects that stand in for real components to facilitate testing. Here are the differences between these concepts:

Faking

Fakes are objects that have working implementations but are not suitable for production use because they take shortcuts to simplify the implementation. They are often used to simulate complex systems or external dependencies in a lightweight manner. For example, an in-memory database can be used as a fake to avoid the overhead of interacting with a real database during tests. Fakes are useful when you need a functional implementation that behaves similarly to the real system but is easier to manage and faster to execute during tests[1][3][7].

Mocking

Mocks are objects that are pre-programmed with expectations about the interactions they will have during the test. They can verify that certain methods were called with specific arguments and can throw exceptions if unexpected calls are made. Mocks are primarily used to test the behavior of the system under test (SUT) by ensuring that it interacts correctly with its dependencies. They are often created using mocking frameworks that allow for dynamic behavior configuration and verification of method calls[1][3][7].

Stubbing

Stubs are objects that provide predefined responses to method calls made during the test. Unlike mocks, stubs do not record interactions or verify that specific methods were called. They are used to provide the necessary data for the SUT to execute without involving real dependencies. Stubs are typically simpler than mocks and are used when the focus is on the state of the system rather than the interactions between objects[1][3][7].

Summary

  • Fakes: Simplified implementations of real components, used to simulate complex systems or external dependencies.
  • Mocks: Objects with pre-programmed expectati...
senior

senior

Gợi ý câu hỏi phỏng vấn

middle

Is writing Unit Tests worth it for already exciting functionality?

middle

Name most common problems observed in performance testing

middle

What is the fundamental value of Unit Tests vs Integration Tests?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào