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

Strange behavior with test class!!
Hi all i have a strange problem with test coverage. It seems that even the test failed in testclass still the code coverage is 100%
Note: I have a validation set by me to give me a error on field values if null.
* I know my code is bad but this is for just testing one senario
trigger webservice2 on Web_Service__c (before insert) { list<Web_Service__c > n= new list<Web_Service__c >(); for(Web_Service__c w: trigger.new){ n.add(w); } for(Web_Service__c w: n){ w.Rss_Url__c=''; } Database.SaveResult[] lsr = Database.update(n, false); }
and the test class:
@isTest private class testwebservice2 { public class applicationException extends Exception {} public static testmethod void testing() { Web_Service__c a= new Web_Service__c (Rss_Url__c='www.h.com'); insert a; } }
What my question is even after if it gives me this error :
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, webservice2: execution of BeforeInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old Trigger.webservice2: line 17, column 1: []
my code covers 100%
And also that can I deploy this code to production with this test failed class??
Hi,
Your code is gettting executed till last statement, So the code coverage is 100%. If you write some other statements after the
Database.upate statement, Code coverage will go down as code fails at this statement.
As per my understanding, This code will not get deployed as test is failing.
Regards,
Sushil
Thanks also i Updated the code can you explain why this also give 100% coverage with no error??
as atp__c has a reequired field, the test should fail right!!
You have changed the object that you were updating earlier. So no error now.
You can't call database operation on object on which trigger is getting invoked.
Yes i know that i intennintentionally wrote like that:
but for this
as atp__c has a reequired field, the test should fail right!!
What do you mean by required field? Have you put any validation rule?
Name is required only if you are keeping it as text field. For Auto number it will automatically take next number in sequence.