#21064 closed enhancement (fixed)
[PATCH] Add JUnit 5 extension for preferences
| Reported by: | taylor.smock | Owned by: | Don-vip |
|---|---|---|---|
| Priority: | normal | Milestone: | 21.07 |
| Component: | Unit tests | Version: | |
| Keywords: | junit5 | Cc: |
Description (last modified by )
#16567 is getting a bit big, so I'm going to make separate tickets for different patches/functionality.
The attached patch does the following:
JUnit5 Extension: Add utilities for basic preferences
Also, move many tests that rely solely on
- JOSMTestRules#preferences
- JOSMTestRules#timeout
- JOSMTestRules#i18n
- JOSMTestRules with no further calls
See:
Attachments (5)
Change History (20)
by , 4 years ago
| Attachment: | 21064.patch added |
|---|
comment:1 by , 4 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 4 years ago
| Milestone: | → 21.07 |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:4 by , 4 years ago
Can you please update the patch? I've changed some tests in the past two weeks. I'll apply it first thing tomorrow morning.
comment:5 by , 4 years ago
| Component: | Core → Unit tests |
|---|
comment:6 by , 4 years ago
| Keywords: | junit5 added; junit 5 removed |
|---|
comment:7 by , 4 years ago
I just did that (on GitLab). Hopefully the CI test stage doesn't time out again (just so that we have a confirmation from a "clean" environment that it doesn't break anything). I'll also upload an updated patch here.
comment:10 by , 4 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
https://github.com/openstreetmap/josm/runs/3084630956?check_suite_focus=true
OverpassDownloadReaderTest is not happy about the change.
comment:11 by , 4 years ago
Awesome. That is one of the tests I didn't modify, since it is still on JUnit4.
It does look like an ordering issue. What is happening is NameFinder.NOMINATIM_URL_PROP is getting initialized elsewhere, and since AbstractProperty sets the preference variable on first load, we have a null preference stored, even when preferences are initialized.
The previous behavior of JOSMTestRules was to avoid cleaning up the preferences class, so this was never a real issue.
Solutions:
- Add
@BasicPreferencesannotation toNameFinderTest. This is easy, but it doesn't help us keep tests isolated, and this may crop up again in the future. - Modify the
@BasicPreferencesannotation to crawl through loaded classes, looking forstaticandstatic finalAbstractProperties, and use reflection to set thepreferencesfield to the currentConfig.getPref()variable. This is harder, may be significantly slower (but may not be as well --@BasicPreferencestypically only runs once per test class).
by , 4 years ago
| Attachment: | 21064.NameFinderAnnotation.patch added |
|---|
NameFinder initializes NameFinder.NOMINATIM_URL_PROP before OsmDownloadReaderTest (depends upon ordering)
comment:12 by , 4 years ago
- attachment:21064.NameFinderAnnotation.patch just modifies
NameFinderTestto have a@BasicPreferencesannotation. While I don't think it is ideal, it does avoid the pitfalls of the other option. - attachment:21064.BasicPreferencesConfigReset.patch iterates through all loaded classes (I make an assumption that we only have one classloader), and sets all
AbstractPropertypreferencesfields to the new preferences. This uses reflection to fiddle withfinalfields, which has some pitfalls. - attachment:21064.BasicPreferencesConfigReset.2.patch is the same as attachment:21064.BasicPreferencesConfigReset.patch, except it additionally resets the
preferencesfields tonull. This is better from a test isolation view, but I can almost guarantee that additional tests will fail.
I'm running a test run with attachment:21064.BasicPreferencesConfigReset.2.patch right now, but it is going to take a little while.
by , 4 years ago
| Attachment: | 21064.BasicPreferencesConfigReset.patch added |
|---|
Reset all static AbstractProperty preferences fields to the new Config.
by , 4 years ago
| Attachment: | 21064.BasicPreferencesConfigReset.2.patch added |
|---|
Additionally reset static AbstractProperty preference fields to null after each test (this may cause other test failures)
follow-up: 15 comment:13 by , 4 years ago
Thanks! For this ticket I'll stick with the simple solution, even if not ideal. Isolating unit tests is a long-term task.



@BasicPreferences extension + porting of tests to use it