0

I have written one Test class in which Test class is working Fine, But Code Coverage is 0% and after running the Test Class i am getting "Selected job is not yet complete in Test Class" .

Trigger

trigger AssetsAllocation on Assets_Allcoation__c (after insert,after update) {

  List<ID> lid =new List<ID>();
   List<ID> listid=new List<ID>();
    Map<ID, ID> myMap= new Map<ID, Id>();

    List<Assets__c> alloctionlist=new List<Assets__c>();
    List<Employee_Name__c> emplsit=new List<Employee_Name__c>();
    Integer i=0;
    for(Assets_Allcoation__c acc:Trigger.new)
    {
        if(acc.Employee__c!=null){
            myMap.put(acc.Assets__c,acc.Employee__c);
            lid.add(acc.Employee__c);
            listid.add(acc.Assets__c);

        }
    }

  //  emplsit=[Select id,Name,(select id,name from Assets_Allcoations__r)from Employee_Name__c where ID IN:lid];
    Map<ID, Employee_Name__c > emp_map = new Map<ID, Employee_Name__c >([Select id,Name from Employee_Name__c where ID IN:lid]);
    alloctionlist=[Select id,Assigned_To__c from Assets__c where ID IN:listid];
    Id emp_id;
    for(Assets__c asst: alloctionlist){
         emp_id= myMap.get(asst.Id);
         Employee_Name__c emp = emp_map.get(emp_id);
         asst.Assigned_To__c= emp.name;
    }

    update alloctionlist;

}

Test Class

@isTest

private class TestAssetsAllocationTrigger{

    private static void TestAssetsAllocationTriggerMethod()
    {

            Assets__c a=new Assets__c();
            a.Name='Test';

            insert a;

            Employee_Name__c e=new Employee_Name__c();
            e.Name='Test';

            insert e;

            Map<ID,ID> testmap=new Map<ID,ID>();

            if(e.Name!=null)
            {
                testmap.put(a.id,e.id);

            }


        map<ID,Employee_Name__c> testEmpId=new Map<ID,Employee_Name__c>([Select id,Name from Employee_Name__c where ID =:e.id]);

        id testid=testmap.get(a.id);
        Employee_Name__c testemp=testEmpId.get(testid);
        a.Assigned_To__c=testemp.Name;

        update a;

   }

}
1
  • Why do you think that this test class would test the assets_allcoation__c trigger? It doesn't insert or update an assets_allcoation. – Doug B Aug 14 '15 at 13:55
2

Try changing your method signature as such:

private static testmethod void TestAssetsAllocationTriggerMethod()
    {

or

@isTest
private static void TestAssetsAllocationTriggerMethod()
    {

If that does not work then I do not think it is something wrong with your code. You may wish to open a support case.

And your class is unnecessarily long, here is a shortened version:

private static testmethod void TestAssetsAllocationTriggerMethod()
    {

            Assets__c a=new Assets__c(
                    Name='Test'
                );

            insert a;

            Employee_Name__c e=new Employee_Name__c(
                    Name='Test'
                );


            insert e;

            system.assertNotEquals(null,e.id,'Employee_Name__c was not inserted');


        a.Assigned_To__c = e.name;

        update a;

   }

And as you seen once it is shortened, it does not make sense what you are actually testing....You are not even inserting an Assets_Allcoation__c so I do not think it will be covered unless there are other triggers creating the records.

2
  • I want a Support Case Because it is not working – Shantanu Mahajan Aug 14 '15 at 13:33
  • 3
    Then submit one.... – Eric Aug 14 '15 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.