You need to sign in to do that
Don't have an account?
Shannon Andreas 1
Help with Apex test code
Hello,
I hope this is an easy one. I was trying deploy a change set and ran in to the following error when trying to validate:
TEST_MassTaskController.myUnitTest(), Details: System.Exception: Assertion Failed: Same value: null Class.TEST_MassTaskController.myUnitTest: line 110, column 1
Here is the test code:
@isTest
private class TEST_MassTaskController {
static testMethod void myUnitTest() {
Test.startTest();
//Create Accounts
Account account1 = new Account();
account1.Name = 'Test_Account_01';
insert account1;
Account account2 = new Account();
account2.Name = 'Test_Account_02';
insert account2;
//Create Contacts
Contact contact1 = new Contact();
contact1.LastName = 'Test_Contact_01';
insert contact1;
Contact contact2 = new Contact();
contact2.LastName = 'Test_Contact_01';
insert contact2;
//Get a profile from SFDC
Profile profile = [select Id from Profile limit 1];
//Create a user
User user = new User();
user.Username = 'Test_user_name@test.com';
user.LastName = 'Test_last_name';
user.ProfileId = profile.Id;
user.Alias = 'tst';
user.Email = 'Test_email@email.com';
user.CommunityNickname = 'Test_nick_name';
user.TimeZoneSidKey = 'GMT';
user.LocaleSidKey = 'en_US';
user.LanguageLocaleKey = 'en_US';
user.EmailEncodingKey = 'ISO-8859-1';
insert user;
//Simulate the page for What Id
PageReference pPageReference = Page.Mass_Task_Action;
pPageReference.getParameters().put('objIds',account1.Id+','+account2.Id);
pPageReference.getParameters().put('retUrl','');
Test.setCurrentPage(pPageReference);
MassTaskController controler = new MassTaskController();
System.assertEquals(controler.showWhoId, true);
controler.getTableDisplayNames();
controler.saveNew();
controler.save();
controler.back();
//Simulate the page for Who Id
pPageReference = Page.Mass_Task_Action;
pPageReference.getParameters().put('objIds',contact1.Id+','+contact2.Id);
pPageReference.getParameters().put('retUrl','');
Test.setCurrentPage(pPageReference);
controler = new MassTaskController();
System.assertEquals(controler.showWhoId, false);
controler.getTableDisplayNames();
controler.getselReminderOptions();
controler.saveNew();
Pagereference pageRef = controler.save();
System.assertEquals(pageRef, null);
controler.back();
controler.task.OwnerId = user.Id;
controler.task.Subject = 'Test_Subject';
controler.task.Status = 'Completed';
controler.task.Priority = 'High';
//Set the reminder
controler.task.IsReminderSet = true;
controler.contact.Birthdate = Date.today();
controler.reminderTime = '23:30';
//Send Email notification
controler.sendNotificationEmailCheckBox = true;
controler.saveNew();
pageRef = controler.save();
110 System.assertNotEquals(pageRef, null);
Test.stopTest();
}
}
I have searched these boards all day today and found no one referencing the System.assertNotEquals. Can anyone explain what that is stating? Also, can you help me to determine where I am missing something? Let me know if you need the Apex Class this is referencing.
Thanks,
Shannon
I hope this is an easy one. I was trying deploy a change set and ran in to the following error when trying to validate:
TEST_MassTaskController.myUnitTest(), Details: System.Exception: Assertion Failed: Same value: null Class.TEST_MassTaskController.myUnitTest: line 110, column 1
Here is the test code:
@isTest
private class TEST_MassTaskController {
static testMethod void myUnitTest() {
Test.startTest();
//Create Accounts
Account account1 = new Account();
account1.Name = 'Test_Account_01';
insert account1;
Account account2 = new Account();
account2.Name = 'Test_Account_02';
insert account2;
//Create Contacts
Contact contact1 = new Contact();
contact1.LastName = 'Test_Contact_01';
insert contact1;
Contact contact2 = new Contact();
contact2.LastName = 'Test_Contact_01';
insert contact2;
//Get a profile from SFDC
Profile profile = [select Id from Profile limit 1];
//Create a user
User user = new User();
user.Username = 'Test_user_name@test.com';
user.LastName = 'Test_last_name';
user.ProfileId = profile.Id;
user.Alias = 'tst';
user.Email = 'Test_email@email.com';
user.CommunityNickname = 'Test_nick_name';
user.TimeZoneSidKey = 'GMT';
user.LocaleSidKey = 'en_US';
user.LanguageLocaleKey = 'en_US';
user.EmailEncodingKey = 'ISO-8859-1';
insert user;
//Simulate the page for What Id
PageReference pPageReference = Page.Mass_Task_Action;
pPageReference.getParameters().put('objIds',account1.Id+','+account2.Id);
pPageReference.getParameters().put('retUrl','');
Test.setCurrentPage(pPageReference);
MassTaskController controler = new MassTaskController();
System.assertEquals(controler.showWhoId, true);
controler.getTableDisplayNames();
controler.saveNew();
controler.save();
controler.back();
//Simulate the page for Who Id
pPageReference = Page.Mass_Task_Action;
pPageReference.getParameters().put('objIds',contact1.Id+','+contact2.Id);
pPageReference.getParameters().put('retUrl','');
Test.setCurrentPage(pPageReference);
controler = new MassTaskController();
System.assertEquals(controler.showWhoId, false);
controler.getTableDisplayNames();
controler.getselReminderOptions();
controler.saveNew();
Pagereference pageRef = controler.save();
System.assertEquals(pageRef, null);
controler.back();
controler.task.OwnerId = user.Id;
controler.task.Subject = 'Test_Subject';
controler.task.Status = 'Completed';
controler.task.Priority = 'High';
//Set the reminder
controler.task.IsReminderSet = true;
controler.contact.Birthdate = Date.today();
controler.reminderTime = '23:30';
//Send Email notification
controler.sendNotificationEmailCheckBox = true;
controler.saveNew();
pageRef = controler.save();
110 System.assertNotEquals(pageRef, null);
Test.stopTest();
}
}
I have searched these boards all day today and found no one referencing the System.assertNotEquals. Can anyone explain what that is stating? Also, can you help me to determine where I am missing something? Let me know if you need the Apex Class this is referencing.
Thanks,
Shannon
It looks like there is null value.
And code coverage is only calculated if your test method runs successfully.
Please try below code.
Let us know if it helps you.
All Answers
It looks like there is null value.
And code coverage is only calculated if your test method runs successfully.
Please try below code.
Let us know if it helps you.
Thank you!!! It worked.
My code coverage went to 0%, but the test passed. What gives?