You need to sign in to do that
Don't have an account?
vibration
test coverage is only 50% for following code
public class New2 {
public Invoice_Statement__c accc {get; set;}
public Line_Items__c accc1 {get; set;}
public New2(){
accc =new Invoice_Statement__c();
accc1 =new Line_Items__c();
}
public PageReference save() {
insert(accc);
accc1.Invoice_Statement__c=accc.id;
insert(accc1);
return (new ApexPages.StandardController(accc)).view();
}
test coverage=50%
my test class
@isTest
private class invtest {
static testMethod void invtest1() {
New2 invo = new New2();
Invoice_Statement__c acccc = new Invoice_Statement__c();
acccc.Description__c='desci';
acccc.Status__c='open';
insert acccc;
Line_Items__c acccc1 = new Line_Items__c();
acccc1.Unit_Price__c=3;
acccc1.Units_Sold__c=4;
acccc1.Invoice_Statement__c=acccc.id;
insert acccc1;
}
}
Hi vibration
I suggest you work through the Force.com Workbook (it looks like you've made a start?), which you can find here:
http://developer.force.com/workbooks as well as An Introduction to Test Methods and the Apex Developer Guide, to get the basics.
At some point in your test you are going to want to invoke:
New2.save();
And check it's return value, and perhaps whether the line items were added (using "assert" and queries).
Jon
All Answers
Yep - looks like it is.
Not sure what your question is.
Do you know that when you run your tests in the web browser, and it says "50%", that you can click on that and see a coloured depiction of your source that that indicates which lines aren't tested?
In this case, it doesn't look like your test method calls "save" at all.
PS. Your test method also doesn't test anything, but I'm hoping that's because you were trying to figure out the code coverage
Yes . i am new in salesforce. code coverage is 50% save part is not tested. plz tell the solution of program
Hi vibration
I suggest you work through the Force.com Workbook (it looks like you've made a start?), which you can find here:
http://developer.force.com/workbooks as well as An Introduction to Test Methods and the Apex Developer Guide, to get the basics.
At some point in your test you are going to want to invoke:
New2.save();
And check it's return value, and perhaps whether the line items were added (using "assert" and queries).
Jon
Thank u very much . 90% code is coverage.
but return statement is not covered.
So let's think about it.
Line 24 is not being executed right?
What will cause that to happen? What will cause execution to stop before Line 24?
Well, the save() method would have to terminate.
What other routes are there for the save() method to terminate?
Aha - Line 20. It has a return right? AND, it's not red - which means it's being executed.
So your code is stopping on Line 20.
So you need another test, with better data, so that the upsert doesn't fail.
If you expected the return of that save to be null, you should have probably done something like:
PageReference rs = mynew1.save();
assertEquals(null, rs); // I expect it to be null
Then of course, you should also try and write code that makes it succeed and NOT return null.
ie.
// some other statements inserting/modifying record
PageReference rs2 = mynew1.save();
assert( rs2 != null);
//perhaps even more, checing the return value.
System.AssertException: Assertion Failed.
@isTest
private class invtest2 {
static testMethod void invtest1() {
Invoice_Statement__c acccc = new Invoice_Statement__c();
acccc.Description__c='desci';
acccc.Status__c='open';
insert acccc;
// acccc= [select Description__c from Invoice_Statement__c where id =:acccc.id ];
// System.assertEquals('desci',acccc.Description__c);
New1 invo = new New1();
invo.save();
PageReference rs = invo.save();
System.assert(rs != null);
}
}
Yes, your assertion failed because it is equal to null. Just like I said. Please read what I said above, and also my first post where I show you some resources.