When writing code that interacts with external resources (for example, using a web service or other network operation), I often structure classes so that they can be "truncated" using a file or some other input method. Thus, I end up using the enveloped implementation to test other parts of the system, and then one or two tests that specifically test the web service call.
The problem is that I do not want to access these external services from Jenkins or while running all the tests for my project (for example, "gradle test"). Some of the services have side effects or may not be available to all developers.
For the moment, I just uncomment and then re-comment the @Test annotation on these specific testing methods to enable and disable them. Turn it on, run it manually to check it, then remember to comment it.
// Uncomment to test external service manually //@Test public void testSomethingExternal() {
Is there a better way to do this?
EDIT: For manual unit testing, I use Eclipse and can just right-click on the test method and run Run As -> JUnit test. But this does not work without annotation (no comment).
source share