Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of function execution in mxunit testcase

I'm using MxUnit as a testing framework for my ColdFusion project. But I'm not sure about, in which order the functions in the testcase is getting executed. I've inserted dummy records in DB for my testing, in beforeTests() and deleting those records in afterTests(). I'm having following functions in my testcase

public void function Read() {
//Block of code
}
public void function Save() {
//Block of code
}
public void function Delete() {
//Block of code
}

But at first Delete() gets executed, so the read() returns "No record Found"(failure message), because the record gets deleted in the delete() itself. So I thought that it is running in alphabetical Order and so I changed the function names accordingly(Read(),Save(),XDelete() - since it is in alphabetical order). Again the same thing is happening.

But it works fine, when I renamed the functions as A_Read(),B_save(),C_Delete().

So someone explain about in which order the functions get executed.

like image 406
Rajesh Manilal Avatar asked Feb 13 '23 13:02

Rajesh Manilal


2 Answers

You can't guarantee what order they will run in, assume it's random.

See http://blog.adamcameron.me/2013/11/unit-testing-mxunit-and-test-scenario.html

For a given test run there is no guarantee what order tests are run in, although in reality it's down to how ColdFusion exposes them in a CFC's metadata, I think. Their execution order is certainly not randomised. But one should not assume any test execution order. And, indeed, each test really needs to be completely discrete from other tests in the CFC

You really need to rethink how you're doing your tests, so they are all independent of each other.

However if you really must: http://blog.bittersweetryan.com/2012/01/using-new-orderedtestdecorator-in.html

like image 183
duncan Avatar answered Feb 28 '23 10:02

duncan


You're probably better off using setUp and tearDown instead of beforeTests and afterTests. That way fresh dummy records will be inserted into the database before each test is run and the tests will not be dependent upon each other.

like image 42
Simon Bingham Avatar answered Feb 28 '23 10:02

Simon Bingham