You need to sign in to do that
Don't have an account?
sarthak das 4
I can't get the error "The 'RejectDoubleBooking' class did not achieve 100% code coverage via your test methods"
Any suggestion pls.Here is my code.
@isTest
private class TestRejectDoubleBooking{
static testmethod void TestDoubleBooking() {
Datetime now = System.now();
Speaker__c speaker = new Speaker__c(First_Name__c='John', Last_Name__c='Smith');
insert speaker;
Session__c session1 = new Session__c(Name='Session 1', Session_Date__c=now);
insert session1;
Session__c session2 = new Session__c(Name='Session 2', Session_Date__c=now);
insert session2;
Session_Speaker__c assignment1 =
new Session_Speaker__c(Session__c=session1.Id, Speaker__c=speaker.Id);
insert assignment1;
Session_Speaker__c assignment2 =
new Session_Speaker__c(Session__c=session2.Id, Speaker__c=speaker.Id);
Database.SaveResult result = Database.insert(assignment2, false);
System.assert(!result.isSuccess());
}
}
@isTest
private class TestRejectDoubleBooking{
static testmethod void TestDoubleBooking() {
Datetime now = System.now();
Speaker__c speaker = new Speaker__c(First_Name__c='John', Last_Name__c='Smith');
insert speaker;
Session__c session1 = new Session__c(Name='Session 1', Session_Date__c=now);
insert session1;
Session__c session2 = new Session__c(Name='Session 2', Session_Date__c=now);
insert session2;
Session_Speaker__c assignment1 =
new Session_Speaker__c(Session__c=session1.Id, Speaker__c=speaker.Id);
insert assignment1;
Session_Speaker__c assignment2 =
new Session_Speaker__c(Session__c=session2.Id, Speaker__c=speaker.Id);
Database.SaveResult result = Database.insert(assignment2, false);
System.assert(!result.isSuccess());
}
}
Greetings to you!
You need to include both the methods in your test class - TestSingleBooking() and TestDoubleBooking(). Please try the below code, I have tested in my org and it is working fine.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas