How to redirect unit test to cfwheels

What would be the right way to unit-test the actions of the controller performing the redirection?

UPDATE: I am the main developer of the CFWheels project. The whole reason I ask this question is that I am currently working on improving the built-in testing framework that we have, and I am wondering how to approach and implement something similar in CFWheels, so that it is easier for developers to test their application.

UPDATE: I figured out how to check this. it seems that we will have to rewrite the internal parts of the wheel controller a bit in order to redirect after the action is completed and after it is transferred back to the dispatcher. the only thing with this approach is that any code after redirectTo () will be run by EXCEPT if you take appropriate precautions before starting work; this includes either passing a return after the redirectTo () statement, or setting up conditional checks in your action to extract the redirectTo () code from another code. This also includes ensuring that nothing is displayed when redirectTo () is executed.

+4
source share
2 answers

Similarly, it becomes much easier to verify if you decompose the redirect mechanism into several functions: a) a function that defines the destination URL, and b) a function that performs the redirect.

So you can easily test function A, and function A is the one you want to test anyway. This is the code for you . This is where your real logic is. FunctionB is not your code; this is ColdFusion gut, and there’s not much point in testing CFLocation.

If you are fulfilling a mission to achieve 100% test coverage, you can conduct 10 tests for a function where you execute all the different branches of your logic, and then one test for function B, which redirects in the way that Terry suggests; therefore this way you only get 1 slow test instead of 10.

You can generalize this approach for use in other scenarios: file systems, web services, http, ftp, email, etc .: "Extract material that you can control and want to test material that you cannot control, and you don’t want to check "

+2
source

You can invoke the controller with the appropriate URL using cfhttp with the redirect set to false. Then check the resulting cfhttp result structure, it should have information about where the redirect will be redirected.

+2
source

Source: https://habr.com/ru/post/1301770/


All Articles