Would anyone be able to help me fix

System.AssertException: Assertion Failed

in my trigger test?

I get the following error message:

System.assertexception assertion failed:Data invalid:Expected:True,Actual:false

Below is the method containing the err-

private static testmethod void testGetMigrateVarietyChangeTypes() {
    //System.assertEquals(true, LG_Util.getMigrateVarietyChangeTypes().contains('Downgrade'), 'Data invalid');
    System.assertEquals(false, LG_Util.getMigrateVarietyChangeTypes().contains('Upgrade'), 'Data invalid');
    System.assertEquals(false, LG_Util.getMigrateVarietyChangeTypes().contains('Change'), 'Data invalid');

Class method-

public static Set<String> getMigrateVarietyChangeTypes() {
    Set<String> migrateVarieties = new Set<String>();

    for (csordtelcoa__Change_Types__c changeType : csordtelcoa__Change_Types__c.getAll().values()) {
      if (changeType.LG_MigrateVariety__c) {

    return migrateVarieties;
  • 2
    Are you creating csordtelcoa__Change_Types__c custom setting in test-context? seems like you have missed this step. – Oleksandr Berehovskyi Oct 3 '17 at 12:56

You need to create your own data when writing a test. See the Apex Developer Guide (emphasis mine):

Isolation of Test Data from Organization Data in Unit Tests

Starting with Apex code saved using Salesforce API version 24.0 and later, test methods don’t have access by default to pre-existing data in the organization, such as standard objects, custom objects, and custom settings data, and can only access data that they create. However, objects that are used to manage your organization or metadata objects can still be accessed in your tests such as:

  • User
  • Profile
  • Organization
  • AsyncApexJob
  • CronTrigger
  • RecordType
  • ApexClass
  • ApexTrigger
  • ApexComponent
  • ApexPage

Whenever possible, you should create test data for each test. You can disable this restriction by annotating your test class or test method with the IsTest(SeeAllData=true) annotation.

Test code saved using Salesforce API version 23.0 or earlier continues to have access to all data in the organization and its data access is unchanged.

Also note from How to Write Good Unit Tests (emphasis mine):

Verify the results are correct

Verifying that your code works as you expect it to work is the most important part of unit testing. It’s also one of the things that Force.com developers commonly neglect. Unit tests that do not verify the results of the code aren’t true unit tests. They are commonly referred to as smoke tests, which aren’t nearly as effective or informative as true unit tests.

A good way to tell if unit tests are properly verifying results is to look for liberal use of the System.assert() methods. If there aren’t any System.assert() method calls, then the tests aren’t verifying results properly. And, no, System.assert(true); doesn’t count.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.