0
@isTest
private class TestRejectDoubleBooking{
    public void TestSingleBooking(){
      static testmethod void TestSingleBooking() {
    Datetime now = System.now();

    Speaker__c speaker = new Speaker__c(First_Name__c='John', Last_Name__c='Smith');
    insert speaker;

    Session__c session = new Session__c(Name='Some Session', Session_Date__c=now);
    insert session;

    Session_Speaker__c assignment =
    new Session_Speaker__c(Session__c=session.Id, Speaker__c=speaker.Id);

    Database.SaveResult result = Database.insert(assignment, false);

    System.assert(result.isSuccess());
}   
    }

}
1
  • 2
    Welcome to SFSE! Your question looks like a message that you are getting compile error. Can you please specific on what problem you are facing or what is your doubt/question. Please go through How to Ask section to understand how to ask.
    – Ashwani
    Sep 20, 2016 at 10:03

1 Answer 1

1

You cannot declare a method within a method. Remove this line:

public void TestSingleBooking() {

And also remove the corresponding closing bracket }.

Correct Code:

@IsTest
class TestRejectDoubleBooking
{
    static testMethod void testSingleBooking()
    {
        // test code here
    }
}

What you are doing instead is trying to declare a method within a method, as stated above. Note also that your methods must be declared testmethod or annotated with @IsTest in order to actually run.

Incorrect Code:

@IsTest
class TestRejectDoubleBooking
{
    public void testSingleBooking()
    {
        static testMethod void testSingleBooking()
        {
            // test code here
        }
    }
}

I also find that careful, consistent use of indentation can make these types of problems much more clear.

You must log in to answer this question.

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