You need to sign in to do that
Don't have an account?
sfdc newbie
System.AssertException: Assertion Failed
Could anyone help me as i have created Test class:
@isTest
private class ChatterAnswersCreateAccountTest {
static testMethod void validateAccountCreation() {
Profile[] p = [SELECT Id FROM Profile WHERE UserType = 'Standard'];
User[] user = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id];
// We cannot create account without a user.
if (user.size() == 0) { return; }
String firstName = user[0].FirstName;
String lastName = user[0].LastName;
String userId = user[0].Id;
Account oAccount = new Account();
oAccount.name = 'TestAccc';
oAccount.Industry = 'Other';
oAccount.Type = 'Previous Customer';
oAccount.Account_Intergraph_Line_of_Business__c = 'MPM';
oAccount.Street_Address__c = 'ABC';
oAccount.City__c = 'CA';
insert oAccount;
List <Account> account = [SELECT name, Industry, ownerId from Account where Id =: oAccount.Id];
System.assertEquals(firstName + ' ' + lastName, oAccount.name);
System.assertEquals(userId, oAccount.ownerId);
}
}
and getting errors like
Error Message System.AssertException: Assertion Failed: Expected: Jhon Tony, Actual: TestAccc
Stack Trace Class.ChatterAnswersCreateAccountTest.validateAccountCreation: line 20, column 1
@isTest
private class ChatterAnswersCreateAccountTest {
static testMethod void validateAccountCreation() {
Profile[] p = [SELECT Id FROM Profile WHERE UserType = 'Standard'];
User[] user = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id];
// We cannot create account without a user.
if (user.size() == 0) { return; }
String firstName = user[0].FirstName;
String lastName = user[0].LastName;
String userId = user[0].Id;
Account oAccount = new Account();
oAccount.name = 'TestAccc';
oAccount.Industry = 'Other';
oAccount.Type = 'Previous Customer';
oAccount.Account_Intergraph_Line_of_Business__c = 'MPM';
oAccount.Street_Address__c = 'ABC';
oAccount.City__c = 'CA';
insert oAccount;
List <Account> account = [SELECT name, Industry, ownerId from Account where Id =: oAccount.Id];
System.assertEquals(firstName + ' ' + lastName, oAccount.name);
System.assertEquals(userId, oAccount.ownerId);
}
}
and getting errors like
Error Message System.AssertException: Assertion Failed: Expected: Jhon Tony, Actual: TestAccc
Stack Trace Class.ChatterAnswersCreateAccountTest.validateAccountCreation: line 20, column 1
In fact I'd say its impossible, given the account name is testAcc and you introduce a space in your concatenation.
What is the purpose of this assert?
System.assertEquals(firstName + ' ' + lastName, oAccount.name);
Du youhave a trigger which populates the account name based on the logged in user?
If yes, then you need to check the account trigger.
If no, then either you can removethis assert or you can update it to :
System.assertEquals('TestAcc' oAccount.name);
But honestly, looks like you have a trigger but you are not asserting correct values.