You need to sign in to do that
Don't have an account?
Mars Rover 570
how to write test class for ifelse condition in constructor
public class MyClass {
public MyClass() {
if(a=='New') {
//Do Something}
else if(a=='Old'){
//Do Something
}
}
public MyClass() {
if(a=='New') {
//Do Something}
else if(a=='Old'){
//Do Something
}
}
Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Devanshu sood
public class MyClass {
public MyClass() {
for(Account a: [Select name from Account]){
if(a=='New') {
//Do Something}
else if(a=='Old'){
//Do Something
}
}
}
Make sure your test class creates at least two accounts. One or more with the value "New", and one or more with the value "Old". When the test calls your code, it will query all the accounts and some will execute the "New" case and others will execute the "Old" case. All of the code will be covered.