I have the following (approximate) structure in my Android application that I am trying to write unit test for:
class EventMonitor { private IEventListener mEventListener; public void setEventListener(IEventListener listener) { mEventListener = listener; } public void doStuff(Object param) {
I want to make sure that when passing certain param values, the correct interface methods are called. Can I do this as part of the standard JUnit framework, or do I need to use an external framework? This is a unit test sample that I would like:
public void testEvent1IsFired() { EventMonitor em = new EventMonitor(); em.setEventListener(new IEventListener() { @Override public void doStuff1() { Assert.assertTrue(true); } @Override public void doStuff2() { Assert.assertTrue(false); } }); em.doStuff("fireDoStuff1"); }
I also start in Java, so if this is not a good test sample, I am ready to change it to something more verifiable.
source share