mocking - How to test the function behavior in unit test? -


If a function calls another function or works, how do I check it? Currently, I must return the value to implement all the tasks so that I can emphasize function return value. However, I think that this method is the PR API because in the output code. I do not need those functions to return the price. Any good solution?

I think the counterfeit thing can be possible solution. I want to know when should I use and when should I use counterfeit goods? Is there a general guide line?

Thanks

Sorry to answer directly but ... Are you sure there is a perfect balance in your test?

I wonder if you are not doing too much testing ? Do you really need to test a task that is assigned to someone else?

Returns for tests only

When you write, you do not want to add return value Only useful for tests , for production No, it blocks your API, which makes it less clear, which is a big cost at the end.

In addition to this, your return value may seem correct for the test, but nothing says that the implementation is returning the return value that matches the implementation, so the exam may be something Also do not prove Anyway ...

Cost

Note that the test has initial cost , the cost of writing the test if the implementation Very easy, the risk of failure is less ridiculous, but even The test of spending is still accumulated (in hundred or thousands of cases, it is becoming very serious).

But more than that, every time you refactor your production code, you probably have to re-apply your tests. That's why the maintenance cost of your tests will be .

Testing the implementation

What a method does (the other methods which call it, etc.) checks, like testing a personal method, has been criticized. There are several points made:

  1. This is delicate and costly : Any code will break the refactoring test, so this maintenance cost increases
  2. Testing a personal method does not bring more security to your production code , why F your production code is not the call is actually akin to confirm the important thing.
  3. When a code effectively delegates to another, the implementation is so simple that the risk of mistakes is very low, and the code almost never changes, so once what works (when You write it down) Never break ...

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -