单元测试方法委托

单元测试方法委托

本文介绍了单元测试方法委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有单元测试,它确实的唯一事情是另一个对象委托工作方法的任何一点?例如:

Is there any point in Unit-Testing a method that the only thing it does is delegate work on another object? Example:

class abc {

    ...

    public void MoveLeft()
    {
        fallingPiece.MoveLeft();
    }

    ...
}



我在做单元测试一些现有的类我有,学习的目的。这似乎有点儿奇怪,做单元测试此MoveLeft()方法,例如。但我不能确定如何将它一直有我做测试先行。

I am doing Unit-Tests for some existing classes I have, for learning purposes. It seems kinda odd to do a Unit-Test for this MoveLeft() method, for example. But I am unsure how would it have been had I done Test-First.

感谢

推荐答案

请问你的代码休息,如果我这样做呢?如果可以,那么你需要一个测试来抓住它。

Will your code break if I do this ? If it would, then you need a test to catch it.

class abc {
    ...
    public void MoveLeft()
    {
        // fallingPiece.MoveLeft();
    }
    ...
}



假设:ABC是公开/裸露型和fallingPiece是一个依赖。如果成立,那么你需要一个测试,测试MoveLeft行为。如果它不是一个公共的类型,那么你需要为大众型XYZ使用ABC作为colloborator /依赖性测试。你不直接测试它,但它仍然需要进行测试。

Assumptions: abc is a public / exposed type and fallingPiece is a dependency. If this holds, then you need a test to test the MoveLeft behavior. If it isn't a public type, then you need a test for the public type XYZ that uses abc as a colloborator/dependency. You don't directly test it but it still needs to be tested.

这篇关于单元测试方法委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 05:12