0
private static testMethod void test() {
    Exception ee = null; 
    try{
        utilclass.disableAll(UserInfo.getUserId());
        Test.startTest();

        initTestData();

        ABCclass abc = new ABCclass();
        Object[] data = abc.abcclassmethod(searchFields, '', null, 0, 0);

        System.assert(data.size() > 0, 'No data available');
        data.clear();

    } catch(Exception e){
        ee = e;
    } finally {
        Test.stopTest();
        utilclass.enableAll(UserInfo.getUserId());
        if(ee != null){
            throw ee;
        }
    } 
}

While executing I am getting the below error:

System.FinalException: Testing has not started

2
  • You're using the method Test.stopTest();. It must be precede by a call of Test.startTest(); Jul 27 '17 at 12:27
  • 3
    long story short -- exception appeared in utilclass.disableAll
    – kurunve
    Jul 27 '17 at 12:28
4

it is possible, when Test.startTest(); is not executed, when utilclass.disableAll(UserInfo.getUserId()); will throw any exception, so you have this error. To fix it enclose testing method with Test.startTest(); Test.stoptest(), so remove stop test from finally block

private static testMethod void test() {
    Exception ee = null; 
    try{
        utilclass.disableAll(UserInfo.getUserId());

        Test.startTest();
            initTestData();
        Test.stopTest();

        ABCclass abc = new ABCclass();
        Object[] data = abc.abcclassmethod(searchFields, '', null, 0, 0);

        System.assert(data.size() > 0, 'No data available');
        data.clear();

    } catch(Exception e){
        ee = e;
    } finally {
        utilclass.enableAll(UserInfo.getUserId());
        if(ee != null){
            throw ee;
        }
    } 
}
0

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.