Using test fragments for unit tests #203
Replies: 3 comments 8 replies
-
In my opinion, you should not feel limited and should proceed following the approach you believe to be the best. |
Beta Was this translation helpful? Give feedback.
-
DisclaimerFirst of all the following is in no way normative for platform development and you should most probably follow the advice of @merks to use what works best for you but I still want to mention some things regarding "test fragments" TestfragmentsActually test-fragments are a workaround for tooling limitations (in the past) and I would not recommend to use them for the following reasons:
|
Beta Was this translation helpful? Give feedback.
-
Historically speaking, JDT didn't differentiate main source from test source, as Maven or Gradle or... do. Therefore in the past having main source and test source in one plugin would easily lead to test only dependencies leaking into main code. However, that's a thing of the past and meanwhile you can (and should!) mark all the test source paths (including other classpath entries) as such. Therefore creating a bundle with main and test code following the Maven source folder conventions or similar is surprisingly easy nowadays. So that former benefit of fragments is gone. IMO these 2 points make fragments less attractive for testing nowadays. That said, at least my company bundle testing code is a wild mix of fragments, bundles, and source folders following or not following maven conventions. So it all works, and you can choose what suits your needs. :) |
Beta Was this translation helpful? Give feedback.
-
Test fragments are great for defining unit tests for internals of a plug-in that are not intended to be accessible via the plug-in's public API (or public at all). Currently, I only find few test fragments in platform code:
I would like to ask if there are specific reasons for not having further test fragments. If I remember correct I once read a discussion about that topic, but unfortunately I can neither recap the contents nor find that discussion anymore.
A concrete reason for the question are our current efforts (in particular those of @akoch-yatta and colleagues at Yatta) to provide multi-monitor HiDPI support for SWT on Windows. Since there is no test fragment for SWT yet, only public classes and methods can be tested properly. Most of the added functionality will, however, not be public (and in particular not be part of the public API, as it is specific to Windows). We would like to provide the new functionality with proper architecture and encapsulation, but we are limited in terms of testability when not using test fragments. Either functionality cannot be tested in an isolated way as it is hidden, or it needs to have higher visibility than actually necessary just to make it addressable via tests.
If there are any reasons for not using test fragments or any other arguments on that topic, we would be interested in them. Otherwise we would like to provide a test fragment for SWT to enhance tests at the unit test level.
Beta Was this translation helpful? Give feedback.
All reactions