Start The World's Best Introduction to TDD... free!

Comments

I just wanted to know whether anyone has tried nesting the concrete tests inside the abstract test like this, and if you have, then how do/did you like it?

package ca.jbrains.junit;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
public abstract class ListContract {
@Test
public void emptyList() throws Exception {
assertTrue(createEmptyList().isEmpty());
}
public abstract List<Object> createEmptyList();
public static class ArrayListRespectsListContract extends ListContract {
@Override
public List<Object> createEmptyList() {
return new ArrayList<Object>();
}
}
public static class LinkedListRespectsListContract extends ListContract {
@Override
public List<Object> createEmptyList() {
return new LinkedList<Object>();
}
}
}

Comments