Nested Method in a Test Case

Say I have 2 test case : city and city_checker

city_checker:

if (isDataAvailable == true) {
	startValidation()
	
	while (checkNextpage && countPage <= 10) {
		startValidation()
		countPage = countPage + 1
		KeywordUtil.logInfo("Iterating page: $countPage")
	}
}

public static void startValidation() {
       void method1() {
              //do something
        }

       void method2() {
              //do something
        }

       void method3() {
              //do something
        }
}

city :

WebUI.callTestCase(findTestCase('city_checker'), [], FailureHandling.STOP_ON_FAILURE)

Then katalon will raise an error something like this (on line method1) :

The method declaration should not be here

I came from python and as my understanding, nested method is can be applied.
Is groovy cannot support it?

Any suggestion will be appreciate.

Thanks

import com.kms.katalon.core.util.KeywordUtil

if (isDataAvailable == true) {
	startValidation()
	
	while (checkNextpage && countPage <= 10) {
		startValidation()
		countPage = countPage + 1
		KeywordUtil.logInfo("Iterating page: $countPage")
	}
}

def startValidation() {
	method1()
	method2()
	method3()
}

def method1() {
	//do something
}

def method2() {
	//do something
}

def method3() {
	//do something
}
1 Like

In Groovy & Java, there isn’t a term “nested method”.

You might want Clousure of Groovy.

A useless example:

def startValidation() {
	def method1 = {
		println "I am method1"
	}
	def method2 = {
		println "I am method2"
	}
	def method3 = { name ->
		println "I am ${name}"
	}
	method1()
	method2()
	method3("Joe")
}
1 Like