I have a test class that works on my org dev, I'm trying to make deploy in another org but it's having a strange behavior, the error is in the first assertEqual:
@isTest
static void testUserStore() {
List<String> stores = new List<String>();
stores = OrderController.getStores();
System.assertEquals(stores.contains('Store 1'), true);
System.assertEquals(stores.contains('Store 2'), true);
}
System.AssertException: Assertion Failed: Expected: false, Actual: true Stack Trace: Class.OrderControllerTest.testUserStore: line 81, column 1
The error doesn't make sense because I'm expecting true, not false, and the result were true!! What's wrong?
I tried to change to only assert, but the error is the same:
@isTest
static void testUserStore() {
List<String> stores = new List<String>();
stores = OrderController.getStores();
System.assert(stores.contains('Store 1'), true);
System.assert(stores.contains('Store 2'), true);
}
System.AssertException: Assertion Failed: true Stack Trace: Class.OrderControllerTest.testUserStore: line 81, column 1
assertEquals(Any expectedValue, Any actualValue)
, but you're putting the "actual value" (stores.contains(...)
) as the first argument. Since you're just doing a true/false here,assert()
is the appropriate method to use. The third argument (or second argument in case of the plainassert()
) is optional but allows you to provide a message to display if the assertion fails.OrderController
with us. Since I don't seeseeAllData=true
(which should almost never be used), I'll guess that you're trying to pull data from a Custom Metadata Type. If that's the case, then you need to deploy your MDT object (part of theCustomObject
fol0der) as well as the MDT records (part of theCustomMetadata
folder).