Test Listeners: @SetUp method never get called

Dear All,

Today I tried the Test Listeners for the first, and I have followed the instruction from Katalon Doc.

I came across the keyword @SetUp and @BeforeTestCase. And I tried to use them and the @SetUp seems never get called.

Here is my sample code:

@SetUp(skipped = false)
void setUpUser() {
println “Setting up …”
if (currentProfile == ‘User1’) {
username = ‘user1’
} else {
username = ‘user2’
}
}

Did I miss any configuration here?

2 Likes

Katalon document “Test Fixtures and Test Listeners (Test Hooks) in Katalon Studio” is poorly written. You are confused with it.

The document uses two terms “Test Fixture” and “Test Listener” without defining them. That’s too bad.

Let me explain by example. In a project I made

  • a Test Case named “Test Cases/TC1”
  • a Test Suite named “Test Suites/TS1”
  • a Test Listener named “Test Listeners/TL1”

See the following screenshot of the project

You can open “TS1” in the “</>Script” tab. You would find a script like this:

import com.kms.katalon.core.annotation.SetUp
import com.kms.katalon.core.annotation.SetupTestCase
import com.kms.katalon.core.annotation.TearDown
import com.kms.katalon.core.annotation.TearDownTestCase

/**
 * Some methods below are samples for using SetUp/TearDown in a test suite.
 */

/**
 * Setup test suite environment.
 */
@SetUp(skipped = true) // Please change skipped to be false to activate this method.
def setUp() {
	// Put your code here.
}

/**
 * Clean test suites environment.
 */
@TearDown(skipped = true) // Please change skipped to be false to activate this method.
def tearDown() {
	// Put your code here.
}

/**
 * Run before each test case starts.
 */
@SetupTestCase(skipped = true) // Please change skipped to be false to activate this method.
def setupTestCase() {
	// Put your code here.
}

/**
 * Run after each test case ends.
 */
@TearDownTestCase(skipped = true) // Please change skipped to be false to activate this method.
def tearDownTestCase() {
	// Put your code here.
}

This is what they call “Test Fixture”.

I think that this naming is inappropriate. Usually “test fixture” means a set of input data for testing. Instead, they should have named it “Test Suite Script”.

What they call “Test Fixture” can contain a @SetUp annotation. But it should not contain @BeforeTestCase annotation.

On the other hand, the “Test Listeners/TL1” looks like this:

import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.AfterTestSuite
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext

class TL1 {
	/**
	 * Executes before every test case starts.
	 * @param testCaseContext related information of the executed test case.
	 */
	@BeforeTestCase
	def sampleBeforeTestCase(TestCaseContext testCaseContext) {
		println testCaseContext.getTestCaseId()
		println testCaseContext.getTestCaseVariables()
	}

	/**
	 * Executes after every test case ends.
	 * @param testCaseContext related information of the executed test case.
	 */
	@AfterTestCase
	def sampleAfterTestCase(TestCaseContext testCaseContext) {
		println testCaseContext.getTestCaseId()
		println testCaseContext.getTestCaseStatus()
	}

	/**
	 * Executes before every test suite starts.
	 * @param testSuiteContext: related information of the executed test suite.
	 */
	@BeforeTestSuite
	def sampleBeforeTestSuite(TestSuiteContext testSuiteContext) {
		println testSuiteContext.getTestSuiteId()
	}

	/**
	 * Executes after every test suite ends.
	 * @param testSuiteContext: related information of the executed test suite.
	 */
	@AfterTestSuite
	def sampleAfterTestSuite(TestSuiteContext testSuiteContext) {
		println testSuiteContext.getTestSuiteId()
	}
}

A Test Listener can contain @BeforeTestCase annotation. But a Test Listener should not contain @SetUp annotation.

@visal.va

I guess, you wrote a @SetUp annotation in a Test Listener. Katalon does not expect @SetUp to be there in a Test Listener, so it never calls the method annotated with @SetUp.

3 Likes

@visal.va - I think you should Put your code into testsuite.

2 Likes