Sometimes when you use Test.loadData() you might receive some confusing error message saying “Validation Errors While Saving Record(s)”, it is hard to understand what is wrong in data so it is possible to use the following code to debug the problem
StaticResource sr = [SELECT Id, Body FROM StaticResource WHERE Name = 'TestData' LIMIT 1]; String body = sr.Body.toString(); String[] fields = body.split('\r\n')[0].split(','); SObject[] records = new List(); String[] lines = body.split('\r\n'); for ( Integer j = 1; j < lines.size(); j++ ) { SObject r = new Custom_Object__c(); String[] data = lines[j].split(','); for (Integer i = 0; i < fields.size(); i++ ) { System.debug(LoggingLevel.ERROR, '@@@ fields[i]: ' + fields[i] + ' + data[i] ' + data[i] ); r.put( fields[i], data[i]); } records.add( r ); } insert records;
So when you run a code like this you will find out the exact problem you face