You need to sign in to do that
Don't have an account?
TehNrd
Question about Unit Testing and setting up currentPageReference()
Whoohooo. I have finally built out a Visual Force page that is ready for prime time but now I need to write the test classes for it.
Here is my stumbling block:
The page is launched from a Page Button on the Lead object ( /apex/mergeLeadToOpp?id={!Lead.Id} )
In the controller the following query is run that uses "System.currentPageReference().getParameters().get('id')"
mylead = [select Id, Name, etc, etc from Lead where ID = :System.currentPageReference().getParameters().get('id')];
Here is my test class (not even close to done) but I can't seem to get it to work. Any help is greatly appreciated.
Message Edited by TehNrd on 04-19-2008 10:12 PM
Here is my stumbling block:
The page is launched from a Page Button on the Lead object ( /apex/mergeLeadToOpp?id={!Lead.Id} )
In the controller the following query is run that uses "System.currentPageReference().getParameters().get('id')"
mylead = [select Id, Name, etc, etc from Lead where ID = :System.currentPageReference().getParameters().get('id')];
Here is my test class (not even close to done) but I can't seem to get it to work. Any help is greatly appreciated.
Code:
public class mergeLeadToOppVFTEST { public static testMethod void testMyController() { Lead l = new Lead( Reseller_First_Name__c = 'Jason', Reseller_Last_Name__c = 'V', Reseller_Email__c = 'jv@f5.com', Reseller_Company_Name__c = 'VenTech', Reseller_Phone__c = '207-69H-8540', Distributor__c = 'Super Disiti', Software_Vendor__c = 'SFDC', Source_code__c = 'abcd' ); insert l; //I think this is where my problem is. Here is what I have tried but with no luck Test.setCurrentPageReference(new PageReference('/apex/mergeLeadToOpp—id=' + l.id)); Test.setCurrentPageReference(new PageReference('Page.mergeLeadToOpp–id=' + l.id)); Test.setCurrentPageReference(new PageReference('Page.mergeLeadToOpp')); mergeLeadToOppVF controller = new mergeLeadToOppVF(); controller.settargetOpp('asdfasd'); controller.mergeLead(); String error = controller.getError(); System.AssertEquals(error,'Link or ID must be at least 15 characters long.'); } }
Message Edited by TehNrd on 04-19-2008 10:12 PM
Error: Compile Error: Method does not exist or incorrect signature: Test.setCurrentPageReference(System.PageReference)
but I think there is something wrong with this sandbox. Anything that refers to the Test class is throwing errors. If I try to run others tests on triggers I have built in the past it says: "No testMethods found in selected Apex code" but there are testMethods and in other sandboxes these have worked fine for months. Also if I try to edit something with this "Test.startTest()" it says:
Error: Compile Error: Method does not exist or incorrect signature: Test.startTest() at line 46 column 17
Ehh, I'll refresh the sandbox on Monday, see it this resolves the issues, and report back.
Message Edited by TehNrd on 04-18-2008 09:36 PM
Thanks,
Jason
Update:
Tried Changing
To:
Still getting the error:
Severity and Description Path Resource Location Creation Time Id
Save error: Method does not exist or incorrect signature: Test.setCurrentPage(System.PageReference) hucks_development/src/unpackaged/classes myExtTests.cls line 5 1214842167843 51681
Message Edited by Scott.M on 06-30-2008 09:12 AM
Jason,
Do you have a class named "Test" and hence have issues when trying Test.startTest or some other test method?
I belive this could be causing some problems when you mention that Test.startTest works only on some sandboxes and only during the upgrade period.
Cheers,
Larry
That was exactly what i had done. Thanks for your post.
I was struggling with this as well.
I looked at my classes and sure enough there was a Test.cls.
Mucho thanks!