English 中文(简体)
多次呼吁对 mo物体进行静态Expec
原标题:Multiple calls to staticExpects on mocked objects

我正在准备为我的控制员撰写震荡实验室的测试案例,迄今为止,我已设法对控制员进行 mo弄,并包括我的控制员职能中使用的 au。 问题似乎是,我可以说是静态的。 只字不提一次,这意味着可以确定只要求一项功能的回报价值,而不必说, 同一测试案件中不止一次。

这是我守则的一部分。

$this->TasksController = $this->generate( Tasks , array(
 components  => array( Session , Auth  => array( User ), ) ));

  $this->TasksController->Auth->staticExpects($this->any())
    ->method( User )
    ->with( userID )
    ->will($this->returnValue(224));
     $this->TasksController->Auth->staticExpects($this->any())
    ->method( User )
    ->with( accID )
    ->will($this->returnValue( some ID here ));

每当我这样做并进行测试时,这个错误就给我。

Expectation failed for method name is equal to when invoked zero or more times Parameter 0 for invocation AuthComponent::user( userID ) does not match expected value. Failed asserting that two strings are equal.

请帮助:

问题回答

您必须具体说明静态方法何时使用thi和gt;at(指数)。

$this->TasksController->Auth->staticExpects($this->at(1))
    ->method( user )
    ->with( userID )
    ->will($this->returnValue(224));

$this->TasksController->Auth->staticExpects($this->at(2))
    ->method( user )
    ->with( accID )
    ->will($this->returnValue( some ID here ));

如果在发出错误信息给你所谓的信息之前,你不能确保每次尝试一次尝试。

--- Expected
+++ Actual
@@ @@
- userID 
+ accID 

最后一点,正确的方法名称是“用户”,而不是“用户”。





相关问题
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() ...

热门标签