I'm doing unit testing in CakePHP. I want to test two of my controllers. My app has different kinds of users. I want to test the results the app return depending on which type of user is logged in. I don't know, however, how to log in to the app from the controller test case. I tried a couple of approaches without success. 1) I tried to log in using the Users controller and then running my test case, and 2) tried to group a web test case with the controller unit test.
我在CakePHP中进行单元测试。我想测试两个控制器。我的应用程序有不同类型的用户。我想测试应用程序返回的结果,具体取决于登录的用户类型。但是,我不知道如何从控制器测试用例登录到应用程序。我尝试了几种没有成功的方法。 1)我尝试使用Users控制器登录,然后运行我的测试用例,2)尝试使用控制器单元测试对Web测试用例进行分组。
Any help would be greatly appreaciated.
任何帮助都会得到很大的帮助。
Thanks.
1 个解决方案
#1
try Mark-story's article on testing controllers. Not really testing units though are you? By definition a unit is the smallest testable part of an application. Creating such a broad big tests of your app seems like a bad idea since the application can not grow without failing tests. I believe you should try to split the issue into lesser parts. In other words making sure users are identified as proper type, and given that type, they cant access specific information they shouldnt.
试试Mark-story关于测试控制器的文章。不是真的测试单位,不是吗?根据定义,单元是应用程序中最小的可测试部分。对应用程序进行如此广泛的大测试似乎是一个坏主意,因为应用程序无法在不失败测试的情况下增长。我相信你应该尝试将问题分成较小的部分。换句话说,确保用户被识别为正确的类型,并且给定该类型,他们无法访问他们不应该的特定信息。
#1
try Mark-story's article on testing controllers. Not really testing units though are you? By definition a unit is the smallest testable part of an application. Creating such a broad big tests of your app seems like a bad idea since the application can not grow without failing tests. I believe you should try to split the issue into lesser parts. In other words making sure users are identified as proper type, and given that type, they cant access specific information they shouldnt.
试试Mark-story关于测试控制器的文章。不是真的测试单位,不是吗?根据定义,单元是应用程序中最小的可测试部分。对应用程序进行如此广泛的大测试似乎是一个坏主意,因为应用程序无法在不失败测试的情况下增长。我相信你应该尝试将问题分成较小的部分。换句话说,确保用户被识别为正确的类型,并且给定该类型,他们无法访问他们不应该的特定信息。