←Older revision |
Revision as of 13:23, 22 August 2011 |
Line 3: |
Line 3: |
| == [[JUnit]] and Switch to [[JDK]]7 == | | == [[JUnit]] and Switch to [[JDK]]7 == |
| | | |
- | [[NetBeans]] uses [[JUnit]] a lot for its own internal testing. For historical reasons, the majority of our existing tests are written using [[JUnit]]3 style and even newly created tests continue to be based on the 3.x style. I want to mention this at the beginning, as I am not sure if the same problems discussed below impact [[JUnit]]4 style tests (although I believe they do). | + | [[NetBeans]] uses [[JUnit]] a lot for its own internal testing. We have invested a lot of time in stabilizing our tests over the last four years. More than 8,000 NetBeans tests are known to pass reliably and about 1,000 others are known to be stable in more than 99% of cases (we mark these as ''randomly failing'' tests). |
- | | + | |
- | We have invested a lot of time in stabilizing our tests over the last four years. More than 8,000 NetBeans tests are known to pass reliably and about 1,000 others are known to be stable in more than 99% of cases (we mark these as ''randomly failing'' tests). | + | |
| | | |
| Anyway, with [[JDK]]7 being out, we started to execute the tests on both [[JDK]]s (6 and 7) to see how many regressions we have. Not being naive, we expected that there would be some (for example [[JDK]]7 defines a broken property editor for all enum types which takes precedence over our own property editor used on [[JDK]]6 and tests verifying the correct behavior correctly fail). But that is OK, one cannot improve a framework without making its [[amoeba]] shape shiver a bit. | | Anyway, with [[JDK]]7 being out, we started to execute the tests on both [[JDK]]s (6 and 7) to see how many regressions we have. Not being naive, we expected that there would be some (for example [[JDK]]7 defines a broken property editor for all enum types which takes precedence over our own property editor used on [[JDK]]6 and tests verifying the correct behavior correctly fail). But that is OK, one cannot improve a framework without making its [[amoeba]] shape shiver a bit. |
Line 13: |
Line 11: |
| === Random Order of Tests === | | === Random Order of Tests === |
| | | |
- | After a week of investigation, I realized and proved (by reading the log files), that the order of executed '''testXYZ''' methods is random on [[JDK]]7. As the version of [[JUnit]] remains unchanged and as it only calls {{JDK|java/lang|Class}}.'''getMethods()''', the only framework to blame for shaking like an [[amoeba]] is the [[JDK]]! | + | After a week of investigation, I realized and proved (by reading the log files), that the order of executed '''testXYZ''' methods is random on [[JDK]]7. As the version of [[JUnit]] remains unchanged and as it only calls {{JDK|java/lang|Class}}.'''getMethods()''', the only framework to blame for shaking like an [[amoeba]] is the [[JDK]]! Just execute following test few times: |
| + | |
| + | <source lang="java"> |
| + | package org.bar; |
| + | |
| + | import org.junit.Assert; |
| + | import org.junit.Test; |
| + | |
| + | public class OrderedTest { |
| + | private static int counter; |
| + | |
| + | @Test public void testZero() { |
| + | Assert.assertEquals(0, counter); |
| + | counter++; |
| + | } |
| + | |
| + | @Test public void testOne() { |
| + | Assert.assertEquals(1, counter); |
| + | counter++; |
| + | } |
| + | } |
| + | </source> |
| + | |
| | | |
| Sure, reading the [[Javadoc]] of the '''getMethods''' method makes it clear that the order of returned methods can be random. But normal [[API]] users are known to be [[clueless]]! Nobody reads [[javadoc]] while things work. And things used to work for the last four years! [[JDK]]6 (and possibly also [[JDK]]5) return the methods in a stable order, defined by the order of methods in the source. | | Sure, reading the [[Javadoc]] of the '''getMethods''' method makes it clear that the order of returned methods can be random. But normal [[API]] users are known to be [[clueless]]! Nobody reads [[javadoc]] while things work. And things used to work for the last four years! [[JDK]]6 (and possibly also [[JDK]]5) return the methods in a stable order, defined by the order of methods in the source. |