English 中文(简体)
我是否应该测试公共部门的职能,只改变物体的内部状况?
原标题:Should I test public class function, that changes only internal state of the object?

I decided to add unit tests to existing project (quite big one). I am using "google toolbox for mac" for various type of STAssert... and OCMock framework.

但是,我认为我作的检验是错误的。 例如,我有以下公共职能:saveData,这并不回去任何东西,只会改变物体的内部状况。 我是否应该测试? 由于保有权原则,我不必对目标执行感到担忧,而我必须依靠私人变量(因为未来这些变量可能会改变/删除)

@implementation Foo
-(void) saveData {
 internalData_ = 88;
}

在实际项目中,这一功能节省了100条线,改变了该类的许多私人变量。

因此,我是否检验? 我以前在单位测试方面经验不多,不能自行决定。

最佳回答

国内已经改变的状态是否影响到后来对该物体的任何呼吁? 如果是的话,你就应当把它列入像一个单位试验中。

  • Test a()
  • Do saveData()
  • Test a() again

即便不是,也好是联合试验。 不是确定其他法典是否会通过使用这种方法而解体,而是自动测试方法的正确执行。 即使这种方法不归还任何东西,它可能仍然有某种合同(“如果我说,必须做到这一点”),而且你应当检查究竟发生了什么,是否发生了什么(例如,在记录中添加一条线,或者说什么)。

现在,如何检查如果这种方法不归还任何东西,则是一个完全问题。 具有讽刺意味的是,这为unit test提供了详细的执行细节。

问题回答

暂无回答




相关问题
run unit tests and coverage in certain python structure

I have some funny noob problem. I try to run unit tests from commandline: H:PROpyEstimator>python src estpython est_power_estimator.py Traceback (most recent call last): File "src est...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there ...

Unit Testing .NET 3.5 projects using MStest in VS2010

There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签