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

Apex tests have stopped working - Average test coverage has fallen below 75%
A whole lot of tests that were working fine are suddenly producing errors on our production environment meaning the test coverage has fallen below 75% and we can't update anything.
While I have found a couple of genuine errors and fixed in the Sandbox ready to deploy, I'm at a loss to understand the majority of them.
Example
System.AssertException: Assertion Failed: Expected: Benchmark, Actual: N/A Class.testUKItemCodes.testUKItemCodes: line 47, column 5 External entry point
When I actually create a record on the object that has the trigger which populates the value Benchmark in a text field, it works fine and I don't get N/A.
But for some reason when the test class does the same action virtually, it gets a different value.
I'm really at a loss as I they were working fine until recently.
We need to update some of the triggers due to product changes and can't because we can't get the test coverage up.
Any help or ideas would be appreciated.
Regards
Kirsty - Livebookings
I would like to see two things
1)Your test method which is failing
2)Trigger which sets te benchmark
Hi there,
I have actually now got it to work on the Sandbox (although have not tried to deploy yet), with the help of a developer in the office. However neither of us understand why what we changed made it work and why it worked previously and then stopped.
An example of a test class that was failing is:
Previously we did not have the line:
In the price plan creation. We assumed that because the item code is set by trigger we did not need to set it here. Adding this line stopped the test throwing an error.
The trigger that sets the value "Benchmark" looks like this:
This when tested on real data works.
Because you are asserting this
And if you will not insert it then this query will give you Item_Code__c as null
And so your assertion will fail.
Reading through this issue I'm unclear on how exactly it was *ever* working, without specifying '1050' for Item_Code__c.
A few thoughts about data in general. In the event that a space was unexpectedly added to any of your codes, assuming the length of Item_Code__c is > 4, then any assertion about it equaling '1050' would fail since it might = '1050 '.In the event that this is possible, adding the .trim() would do the trick. But from a code maintenance and readability perspective, I'd consider refactoring away from hundreds of literals in conditional statements.
Using a list of codes, or lists of codes that each represent a return type, along with a method to evaluate a specific Item_Code__c value against, would be cleaner - imo.
Hi All,
Thanks for the advice. I'm not a developer, so I've cobbled it together as best I can. It was definitely working though. I think I did not specifiy the item code on the insert as I assumed the trigger would insert it.
Regards
Kirsty