Forum Discussion

khvadagiani's avatar
New Member
3 years ago

NullPointerException when trying use "testCase" inside the class

Hello. I want to create my own jar file to avoid code duplication. When I created class and tested it without jar in the groovy test step, I got this error;

Cannot get property 'testCase' on null object. I need get test step name in my code. Same error when i'm calling same class from jar There is code example:


class TestClass {

private static def log
private static def context
private static def testRunner
private static def testCase

TestClass(log, context, testRunner,testCase) {
this.log = log
this.context = context
this.testRunner = testRunner
this.testCase = testCase

public static String GetTestSuiteName(){

def name = testRunner.testCase.testStep.getName();

return name


1 Reply

  • KarelHusa's avatar
    Champion Level 2

    khvadagiani ,

    you haven't initialized the values of the properties (testRunner, testCase etc.), so they are set to null.


    When you invoke testRunner.testCase.testStep.getName() the testRunner property is null, so you get the error.


    I am not sure what is your goal but setting static (class) properties within the constructor seems confusing to me.


    Best regards,