Tuesday, December 13, 2011

Gradle is easy: Groovy tests

Today in Unit Testing, an evil framework class hid my important return value away in a private field.

Groovy to the rescue!

So far, all our code and tests are in Java. It took only two lines in build.gradle, as specified in the gradle documentation, and poof.

I put my little test class in src/test/groovy/package/structure, typed "gradle build" and wa-la! The results from the groovy test show up right along with the Java tests. Sweet.

class SomethingTest {
def email = "blah@blha.com";

UsefulClass usefulClass
CheckEmail subject

void setup() {
usefulClass = mock(UsefulClass.class);
subject = new Something(userService);

void falseWhenEmailFound() {
when(usefulClass.find(email)).thenReturn(new Thingie());

Reply<Boolean> result = subject.methodUnderTest();

assertEquals result.entity , Boolean.FALSE // see? that mean old private field is right there for the testing.

1 comment:

  1. There are many talk concerning Series LLCs. A great number of are questioning if they're an intelligent idea. The quick answer is which they aren't : they never have been analyzed, giving these limited applications should they have any in any way. www.scorespro.com