Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to test Java app operating directly on external API
    primarykey
    data
    text
    <p>After comming from Ruby world, I'm having little problems doing TDD in Java. The biggest issue is when I have application that is just communicating with external API.</p> <p><strong>Say I want to just fetch some data from Google Calendar</strong>, or 5 tweets from some Twitter user and display it.</p> <p>In Ruby, I don't have any problems, because <strong>I can monkey-patch the API library in tests directly</strong>, but I have no such option in Java.</p> <p>If I think about this in terms of MVC, my model objects are directly accessing the API through some library. The question is, <strong>is this bad design? Should I always wrap any API library in some interface, so I can mock/stub it in Java?</strong></p> <p>Because when I think about this, <strong>the only purpose of that interface would be to <em>simulate</em> (please don't kill me for saying this) the monkey-patch.</strong> Meaning that any time I use any external resource, I have to wrap each layer in interface that can be stubbed out.</p> <pre><code># do I have to abstract everything just to do this in Java? Twitter.stub!(:search) </code></pre> <p>Now you might say that I should always abstract away the interface, so I can change the underlying layer to anything else. But if I'm writing twitter app, I'm not going to change it to RSS reader.</p> <p>Yes, I can add for example Facebook and then it would make sense to have interface. But when there is no other resource that can be substituted for the one I'm using, than I still have to wrap everything in interfaces to make it testable.</p> <p><strong>Am I missing something, or is this just a way to test in the Java world?</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload