I recently came across a situation where every bit of problem is attributed to the technology. It started with the criticism that the problems we have are all due to groovy and then matured to grails.
- The latest entrant into this club is the JUnit 4. There was a issue when we run a grails test suite, one of the integration tests failed. It turned out that the mocking in one of the unit tests were wrong and that left few entries in the database.
A mocked unit test leaving entries in the DB.
Thats the same surprise, i too had. This led us to quoting that Junit 4 is having issues.
I never believed on that and on further investigating, it turned out that when we run the grails unit and integration test together:
- The test classes are loaded and mocked.
- The unit test added rows of the mock class.
- Since the classes are loaded in common for both (some part of it is custom), the mocked class was the same that the integration test also used.
That was the reason that there were so called records left behind in the DB. Actually it never went to the DB itself.
So what made that to be cleared off when we moved to Junit 3 back. Grails adds a metaclass to the GroovySystem.metaClassRegistry when mockDomain, mock… methods are called for the corresponding class. These metaClasses are by default cleared by the tearDown method in the GrailsUnitTestCase.
So when we take up the data setup in Junit 4, we also are given the responsibility of clearing the data back, which can be achieved by a simple call to the GroovySystem.metaClassRegistry clear or the original tearDown call itself.
Ok…. How many times we have been in the same kind of situation and we have just blamed technology for the problems which we introduced…
The problem with this kind of thoughts is:
- Real problem wont be identified
- Different forms of the same problem would occur
- Nothing to learn situations …
In order to effectively address this, We have to move towards a thought process where the problem and its root causes take the centre stage than a opinion that is not backed by data…