Last active
August 29, 2015 14:06
-
-
Save alexsnaps/f42557d008e2ed37f2b1 to your computer and use it in GitHub Desktop.
SPI testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107/ | |
api/ | |
core/src/main <- defines say Store | |
core/src/test | |
core/src/TCK <- defines the TCK tests that every Store should pass (StoreTester.java) | |
impl/src/main <- defines OnHeapStore.java | |
impl/src/test <- depends on core:TCK, unit tests OnHeapStore and makes it pass TCK | |
other/src/main <- defines SomeOtherStore.java | |
other/src/test <- depends on core:TCK, unit tests SomeOtherStore and makes it pass TCK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testStoreSPI() { | |
SPITester tester = new StoreTester(new Factory<OnHeapStore>()) | |
.runTestSuite() | |
.throwJUnitException(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SPITester<T> { | |
protected final Factory<T> factory; | |
public SPITester(Factory<T> factory) { | |
this.factory = factory; | |
} | |
public TestReport runTestSuite() { | |
TestReport report = new TestReport(); | |
for(Method m : findAllTestMethods()) { | |
try { | |
m.invoke(); | |
report.addSuccess(m); | |
} catch(TestFailure f) { | |
report.addFailure(m, f); | |
} | |
} | |
return report; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StoreTester extends SPITester<Store> { | |
@TestMethod | |
public void testSomething(Store s) { | |
Store store = this.factory.newInstance(); | |
store.put("foo", "bar"); | |
// assert?! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was looking at this built-in Parameterized method