2
<apex:page controller="MyController" 
       action="{!IF($Profile.Name != 'xyz', 
  URLFOR($Action.MyObj__c.List, $ObjectType.MyObj__c), NULL)}">

other markup goes here

 </apex:page>

As you can see here, I have a controller and a page that would be displayed only if the profile IS xyz. If the profile is NOT xyz, it takes them to the list view of the object.

Question: Will I be able to test this apex:page action (page redirect to list view) in a test class? If yes, how to do it? I know that we can only test "apex controller" code in the test class and not the "markup" code but wanted to be sure.

  • Nope you can't write a unit test for it. Functional testing is the way to go. – Adrian Larson May 10 '17 at 20:41
1

My first thought is that this isn't something to put through unit testing, but rather something to put through functional testing.

Selenium is a tool that can help out with this, and there a variety of tutorials and blog posts that can help get you started such as this one by Jitendra Zaa

  • Thanks Derek, that's my thinking too. but wanted to be doubly sure that I'm not missing any "security aka profiles based" testing via unit tests. – JJSHHS May 10 '17 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.