Hi, please help me with this strange behaviour) I ...
# announcements
m
Hi, please help me with this strange behaviour) I use testNG, and my lateinit variable is not initialized in @ BeforeSuit
Copy code
open class BaseTest {
    lateinit var testDataConst: MutableMap<String?,Int?>

    @BeforeSuite
    fun setup() {
        testDataConst = prepareBaseData(conf[system.user],conf[system.password])
        println(testDataConst) <<< here testDataConst is initialized
    }
But in Test class testDataConst is uninitialized
Copy code
class AddCustomer : BaseTest() {
    @ Test
    fun addCustomer() {
        println(testDataConst)  <<< Here it is an error
    }
}
How could I solve it?
a
@mike_shysh do you include both classes in your Suite?
m
I am not using testng.xml at all. Just run all classes with Test annotation as it expected by default
BaseTest class without Test annotation
c
@mike_shysh Is the
BeforeSuite
method in your base test class invoked at all?
m
yes, i have posted a solution brlow the answer
c
Yes reading the solution
that's weird
m
static?
c
Since it's a BeforeSuite, it's fine to put it in a companion object but still
I don't understand why your original code didn't work
m
its because of testng
testng run beforesuit in separate thread
c
It should still set that field
m
thats why we need a static variable
yes, it sets tje field but it is not affected in other threads
c
Not sure what you mean
m
for example, if i set the same variable in beforeClass it will work
all my tests in inherited classes, as a result common variable is not visible
with static it work
detailed asnwer requires additional invrstigation) need to dig into testng)
c
@mike_shysh Feel free to follow up on our Google group
m
could you give me a link?)