Git Product home page Git Product logo

Comments (3)

rollbear avatar rollbear commented on August 14, 2024

You need to make the A member accessible in the test so that you can place an expectation on it. One traditional technique for this is dependency injection, i.e. you create your B with the mocked A for the test.

from trompeloeil.

git45016683 avatar git45016683 commented on August 14, 2024

Yeah, I know what you mean, but that's a real huge workload, because there's a lot of historical code (T_T). And they are running at product....
So, i want to found some solution that can integrated unit testing without requiring too many source code changes。
There are many codes like demo in historical code。Although not the best, but it work。 So i can not change every class to dependency injection。
Thanks。

from trompeloeil.

rollbear avatar rollbear commented on August 14, 2024

Well, the library can only work within the rules of the language. For this to work you need:

  1. To ensure that in the test, the member m_pObj points to a mock object.
  2. Access to the mock object from the test code, and its type known, at compile time, in the test to be a mock.

With those you can place expectations on the mock and test your code. If those are not acceptable, then I'm afraid I cannot help.

from trompeloeil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.