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
  • 1
    You're using the method Test.stopTest();. It must be precede by a call of Test.startTest(); Jul 27, 2017 at 12:27
  • 3
    long story short -- exception appeared in utilclass.disableAll
    – kurunve
    Jul 27, 2017 at 12:28

1 Answer 1

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

You must log in to answer this question.

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