0

I am creating unit tests to test a trigger that makes a calculation with particular variables depending on the value of a different. I believe the code below is correct, however I cannot figure out the source of the error I keep getting. I have tried everything I can think of to find the source of the error. Please help! Thank you!

Error I receive:

BuildComponentBITriggerTest: expecting right curly bracket, found 'insert'

@isTest

public class BuildComponentBITriggerTest {
        static testMethod void triggerTestMethod() {

        //Create a new test build component, Insert Estimated Build Hours for new components after calculation
        Build_Component__c testBuildComp = new Build_Component__c(Manual_Override__c='False', Scale__c='2', Type__c=Component_Name__c(Phase__c='Build'));
        insert testBuildComp;
        testBuildComp = [SELECT Estimated_Build_Hours__c FROM Build_Component__c WHERE Type__c = Component_Name__c(Phase__c='Build') IN :testBuildComp];
        System.assert(testBuildComp = [SELECT id, Estimated_Build_Hours__c FROM Build_Component__c WHERE id=: testBuildComp.id]);

        }
}           

3 Answers 3

1
Build_Component__c testBuildComp = new Build_Component__c(Manual_Override__c='False', Scale__c='2', Type__c = Component_Name__c.Phase__c = 'Build');

Something's wrong with Type__c=Component_Name__c.Phase__c='Build'. Maybe first = or dot (.) after Name__c is typo.

1
  • This is the line of code that it is covering: if(e.Component_Name__c == c.Type__c){ How can I say that I want to assign the value of Component_Name_c which has a phase value of 'Build' to Type_c? Commented Sep 17, 2014 at 1:05
0

You need to put your code in a test method.

Something like

@isTest
 public class BuildComponentBITriggerTest {
        static testMethod void yourTestMethod(){
        //your code...
     }
 }

Edit: Also your assertEquals() is wrongly called. Reference Link

Use this Salesforce document on Testing

5
  • I changed it and now I am getting the following error: expecting a colon, found 'Component_Name_.Phase_c' @isTest public class BuildComponentBITriggerTest { static testMethod void triggerTestMethod() { Commented Sep 17, 2014 at 0:58
  • Still getting an error with this: @isTest System.assert(testBuildComp = [SELECT id, Estimated_Build_Hours__c FROM Build_Component__c WHERE id=: testBuildComp.id]); } } Commented Sep 17, 2014 at 1:11
  • Can you first accept the edit and then update your recent code in question
    – A-d
    Commented Sep 17, 2014 at 1:13
  • Just updated. Sorry I am new to stackexchange. Thank you. Commented Sep 17, 2014 at 1:17
  • Well as I have pointed out in my answer your System.assertEquals() method is incorrectly called. You need to pass two values as parameters and they are matched in assertEquals(). Check the reference link I've given and get it correct.
    – A-d
    Commented Sep 17, 2014 at 1:30
0

Try Like This , It might help :

  @isTest

    public class BuildComponentBITriggerTest {
            public static testMethod void triggerTestMethod() {        
                //Create a new test build component, Insert Estimated Build Hours for new components after calculation
              public List<Build_Component__c> lstBC = new List<Build_Component__c>();

               Build_Component__c testBuildComp = new Build_Component__c(Manual_Override__c='False', Scale__c='2', Type__c=Component_Name__c(Phase__c='Build'));
            insert testBuildComp;

            lstBC= [SELECT Estimated_Build_Hours__c FROM Build_Component__c WHERE Type__c = Component_Name__c(Phase__c='Build') IN :testBuildComp];

            System.assert(testBuildComp.Scale__c,'2');

            }
    } 

You must log in to answer this question.

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