Below is a test class that is driving me crazy. I even tried deleting it via Eclipse but I cannot save to server because of this error. I keep getting the following error message:

System.Exception: Assertion Failed: Expected: Select Name,Id From Account Where Name like '%United Partners%', Actual: Select Id,Name From Account Where Name like '%United Partners%' Stack Trace: Class.TestSearchController.t1: line 18, column 1

I want to blame the wildcards %. Perhaps I am missing something more fundamental. Please point this scrub in the right direction.

Test Class below:

private class TestSearchController{

public static testmethod void t1(){

    Set<String> displayFieldNames = new Set<String>();    
    String tableName = 'Account';

    Map<String, String> searchFieldValues = new Map<String, String>();
    searchFieldValues.put('Name', 'United Partners');

    List<String> defaultWhereClause = new List<String>();
    String result   = 'Select Name,Id From Account Where Name like \'%United Partners%\'';
    String query    = SearchLib.buildQueryString( tableName, displayFieldNames, defaultWhereClause, searchFieldValues, new Map<String, String[]>() );
    System.assertEquals( result,query );    

  • 1
    There's something weird in those strings. Try turning them into JSON to see the difference. Nov 26, 2015 at 5:20

3 Answers 3


System.assertEquals does strig comparison in above case and if you will compare both of your string

Select Name,Id From Account Where Name like '%United Partners%'

Select Id,Name From Account Where Name like '%United Partners%'

you can notice the difference kindly make the change accordingly and you are good to go after that.


What I can see is your Expected Result and the Actual result has different String values due to some un-ordered list of fields.

However if you are not sure about the order of fields list you can use String.contains() method for the assertion. This will allow you to test the string content rather than the entire string.

// you can append all of your fields here, use any other efficient mechanism
boolean isContains = query.contains('Select') && query.contains('Idy') &&  query.contains('Name');
System.assertEquals( true,isContains );

The strings are different. The Name/Id are switched between strings.

Just update your expected string to match it. An alternate way of handling it is to check whether particular phrases are contained within the query string.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .