Hi, I need to add file on the fly (generate file)....
# announcements
m
Hi, I need to add file on the fly (generate file). What is the most reliable way to do so? I think that generating file to /*out*/test/resources is not a good idea, isn't it?
g
It doesn’t look related to Kotlin, but maybe you improve your question and give a bit more context
m
I need a file as a test data. I could create this file at the runtime only. Then I need to use it. What is the best way to do it?
m
I think that hardcoded fullpath URL is not a good idea.
😃
Tmp file thats exactly what I have now
g
So what is problem with it?
m
I want to get rid of clearing up stage
g
No need to clearing it
it will be saved by default in tmp dir and remove on JVM shutdown
m
Then it smt strange
coze I have a lot of files on host machine
g
just call deleteOnExit after creation
m
oh, thanks I will look into it
g
also if you use it for test, than it usually responsibility of test to cleanup files and other resources in
@After
method
but
deleteOnExit()
is also fine for most cases
m
Copy code
@AfterClass
    fun deleteTestFile(context: ITestContext) {
        val tmpFile: File = context.getAttribute("fileWithEmergencyUnits") as File
        if (tmpFile.exists()) tmpFile.delete()
    }
Thats what I have now
but Thanks for pointing me to deleteonExit i will try
b
@mike_shysh Probably TemporaryFolder test rule is what you need
m
I have testng, but thanks for info