Skip to content

Instantly share code, notes, and snippets.

@mariuszs
Created January 21, 2014 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariuszs/8547868 to your computer and use it in GitHub Desktop.
Save mariuszs/8547868 to your computer and use it in GitHub Desktop.
Fragile test
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.Arrays;
import java.util.List;
public class FooBarTest {
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
private FooBar toTest = new FooBar();
@Test
public void getMethodThrowsException_whenListHasTooManyElements() throws Exception {
List<String> listWith101Elements = Arrays.asList(new String[101]);
exceptionRule.expect(IllegalArgumentException.class);
toTest.getMethod(listWith101Elements);
}
public class FooBar {
public int getMethod(List<String> code) throws IllegalArgumentException {
code.add("Foo"); // this change fail whole test
if (code.size() > 100)
throw new IllegalArgumentException();
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment