You need to sign in to do that
Don't have an account?

Create a set up test method?
Hi All,
How can I create a helper method in my test class to accomodate common code? It doesnt seem to be possible?
I have this:
private Opportunity setUpOpportunityToTest() { ... }
but its gives me an error when I try to call it: using
setUpOpportunityToTest();
or
this.setUpOpportunityToTest();
?
Thanks
Dan
In reply to my own message should the above work?
Public class myTesting {
Public opportunity setupToTest() { .....}
public class doMyFirstTest() {
myTesting x = new myTesting;
Opportunity testingOpp = x.setupToTest();
.....
}
} // myTesting
or
Public class myTesting {
Opportunity testingOpp;
public void setupTestingOpp() {
testingOpp = new Opportunity(...);
}
public doMyFirstTest() {
myTesting x = new myTesting();
x.setupTestingOpp();
// When you want to use the testing Opp, reference it with x.
controller.doSomeTestOnAnOpportunity(x.testingOpp);
}
}
Second method might be more useful if you have a lot of data structures to setup, and if your setup itself may require several methods.
Best, Steve.
Hi,
Thanks for the reply.
I thought tests had to be marked as Private? and methods with testMethod?
Thanks
Hi Again,
I solved my issue by using a static method, Should have done that first !!
Thanks Again
My apologies... I was just typing it in and I was more focused on explaining the class/data/method structure to create reusable testing structures within a single testing class.
Yes, the outer class should be private. Yes, you have to use static testMethods.
Best, Steve.