You need to sign in to do that
Don't have an account?
Peter Kaye
Code Coverage Problem - Simple Trigger
I am trying to rehearse trigger deployment with a simple test example. Here is the trigger and the test code.
This is the error message.
This is the information from the developer console
The trigger coverage is 100% which I thought was enough.
I am obviously missing something important so I'd apprecaite any help to:
trigger HelloWorldTrigger on Book__c(before insert) { Book__c[] books = Trigger.new; MyHelloWorld.applyDiscount(books); } @isTest private class HelloWorldTestClass { static testMethod void validateHelloWorld() { Book__c b = new Book__c(Name='Behind the Cloud', Price__c=100); System.debug('Price before inserting new book: ' + b.Price__c); // Insert book insert b; // Retrieve the new book b = [SELECT Price__c FROM Book__c WHERE Id =:b.Id]; System.debug('Price after trigger fired: ' + b.Price__c); // Test that the trigger correctly updated the price System.assertEquals(90, b.Price__c); } }I have successfully deployed the trigger but it it fails to function because of insufficient code coverage.
This is the error message.
This is the information from the developer console
The trigger coverage is 100% which I thought was enough.
I am obviously missing something important so I'd apprecaite any help to:
- Identify what code I need to add to the test class above to meet the coverage requirements.
- Explain how I can tell from the developer console whether tests for other triggers will pass coverage requirements.
You need to deploy the test class to the destination org along with the trigger as part of the changeset. Are you doing that or is your test class only in the source org ? If so that is your issue as your test class looks fine.
All Answers
You need to deploy the test class to the destination org along with the trigger as part of the changeset. Are you doing that or is your test class only in the source org ? If so that is your issue as your test class looks fine.