Skip to content

Instantly share code, notes, and snippets.

@akiellor
Created September 6, 2011 08:59
Show Gist options
  • Save akiellor/1197027 to your computer and use it in GitHub Desktop.
Save akiellor/1197027 to your computer and use it in GitHub Desktop.
RSpec Style Runner for JUnit
@RunWith(BehaviourRunner.class)
@ItBehavesLike(ListBehaviours.class)
public class ArrayListTest {
@Subject ArrayList<String> list(){
return new ArrayList<String>();
}
}
@RunWith(BehaviourRunner.class)
@ItBehavesLike(ListBehaviours.class)
public class LinkedListTest {
@Subject LinkedList<String> list(){
return new LinkedList<String>();
}
}
public class ListBehaviours {
@It void shouldAddElements(List<String> subject){
assertThat(subject, hasSize(0));
list.add("An element");
assertThat(subject, hasSize(1));
}
@It void shouldRemoveElements(List<String> subject){
assertThat(subject, hasSize(0));
list.add("An element");
assertThat(subject, hasSize(1));
assertThat(subject, contains("An element"));
list.remove(0);
assertThat(subject, hasSize(0));
}
}
@RunWith(BehaviourRunner.class)
public class StringTest {
@Subject String string(){ return "Some string"; }
@It void shouldStartWithSome(String subject){
assertThat(subject, startsWith("Some"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment