I wrote code on salesforce and to produce unit tests you need to cover at least 75% .
I came across that classOnewhich calls methods from classTwoshould also cover the classTwounit test inside classOne, even if it is already done in the classTwofile.
MyClassTwo File
public with sharing class ClassTwo {
public String method1() {
return 'one';
}
public String method2() {
return 'two';
}
public static testMethod void testMethod1() {
ClassTwo two = new ClassTwo();
String out = two.method1();
system.assertEquals(out, 'one');
}
public static testMethod void testMethod2() {
ClassTwo two = new ClassTwo();
String out = two.method2();
system.assertEquals(out, 'two');
}
}
MyClassOne File
public with sharing class ClassOne {
public String callClassTwo() {
ClassTwo foo = new ClassTwo();
String something = foo.method1();
return something;
}
public static testMethod void testCallClassTwo() {
ClassOne one = new ClassOne();
String out = one.callClassTwo();
system.assertEquals(out, 'one');
}
}
The test result of MyClassOne would not return 100% test coverage, since it says that I did not include the MyClassTwo method2 () part inside the MyClassOne file.
But I already wrote a unit test for MyClassTwo inside the MyClassTwo file, as you can see.
So does this mean that I need to copy and paste the unit test into the MyClassTwo file in MyClassOne?
100% - , . ClassA ClassB....? ?
, mock- salesforce? , ..
http://sites.force.com/answers/ideaView?c=09a30000000D9xt&id=087300000007m3fAAA&returnUrl=/apex/ideaList%3Fc%3D09a30000000D9xt%26category%3DApex%2B%2526%2BVisualforce%26p%3D19%26sort%3Dpopular
UDPATE
, ClassOne 100%, classTwo method2()