单元测试中的Nullpointer异常

时间:2014-09-06 18:39:03

标签: java unit-testing grails groovy

我正在研究Groovy Grails应用程序,特别是目前我正在开发一个允许我生成PLSQL的服务。我遇到了一些问题,但是我在下面用我的单元测试来解决这个Null指针异常的问题。

以下是错误消息:

显示java.lang.NullPointerException 在com.bt.mlp.TemplatingService。$ tt__buildTemplateStepSql(TemplatingService.groovy:59)at com.bt.mlp.TemplatingServiceSpec.Can为TemplateStep创建PLSQL(TemplatingServiceSpec.groovy:113)

如果我点击第一个NullPointer,我会在第二个代码块中转到def result =

如果我点击第二个NullPointer,我会在单元测试中将def result = service.buildTemplateStepSql(templateStep)带到void "Can create PLSQL for TemplateStep" () { setup: createTemplateStep() def validString = """ select sysid into v_mt_sysid from template where name = 'Add FASTE 60 Card'; MLP_TEMPLATE_CP.TEMPLATE_STEPS_INS(IN_MT_SYSID => v_mt_sysid ,IN_STEP => 'step' ,IN_VALIDATION_PROCEDURE => 'Procedure' ,IN_ACTION_PROCEDURE => 'MLP_CARD_INFILL' ,IN_TRANSACTION_TABLE => 'Table' ,IN_DISPLAY_LABLE => 'Capture plan inputs' ,IN_WINDOW_LABLE => 'Capture plan inputs' ,IN_CANCEL_PROCEDURE => 'Cancel Procedure' ,IN_END_PLAN_PHASE => 'Designed' ,IN_MFOUT_FLAG => 'N' ,IN_STEP_SEQ => 1 ,IN_SWF_NAME => 'Name' ,OUT_TS_SYSID => v_ts_sysid ); """ when: def templateStep = TemplateStep.findByStep("step") def result = service.buildTemplateStepSql(templateStep) then: result == validString }

单元测试:

def buildTemplateStepSql(TemplateStep templateStep) {
    println templateStep
    def result =
    """

            select sysid into v_mt_sysid from template where name = 'Add FASTE 60 Card';
            MLP_TEMPLATE_CP.TEMPLATE_STEPS_INS(IN_MT_SYSID => v_mt_sysid
            ,IN_STEP => '${templateStep.step}'
            ,IN_VALIDATION_PROCEDURE => '${templateStep.validationProcedure}'
            ,IN_ACTION_PROCEDURE => '${templateStep.actionProcedure}'
            ,IN_TRANSACTION_TABLE => '${templateStep.transactionTable}'
            ,IN_DISPLAY_LABLE => '${templateStep.displayLable}'
            ,IN_WINDOW_LABLE => '${templateStep.windowLable}'
            ,IN_CANCEL_PROCEDURE => '${templateStep.cancelProcedure}'
            ,IN_END_PLAN_PHASE => '${templateStep.endPlanPhase}'
            ,IN_MFOUT_FLAG => '${templateStep.mfOutFlag}'
            ,IN_STEP_SEQ => '${templateStep.stepSeq}'
            ,IN_SWF_NAME => '${templateStep.swfName}'
            ,OUT_TS_SYSID => v_ts_sysid );

    """

    return result

}

正在测试的代码:

{{1}}

非常感谢任何帮助。

0 个答案:

没有答案