https://github.com/barryiwhite/partialstub
PartialStub is a utility for instantiating partially implemented interfaces in the form of abstract classes
https://github.com/barryiwhite/partialstub
java mocking testing testing-tools
Last synced: 8 months ago
JSON representation
PartialStub is a utility for instantiating partially implemented interfaces in the form of abstract classes
- Host: GitHub
- URL: https://github.com/barryiwhite/partialstub
- Owner: barryiwhite
- License: apache-2.0
- Created: 2022-09-22T13:17:36.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-24T11:01:31.000Z (almost 4 years ago)
- Last Synced: 2024-12-27T09:41:47.371Z (over 1 year ago)
- Topics: java, mocking, testing, testing-tools
- Language: Java
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PartialStub
I am not a fan of mocking frameworks. Too many times I have seen mocks over-used, used incorrectly or even tests that
are just plain wrong because the developer did not understand the API. I also find that tests become over-complicated
and difficult to understand. In the vast majority of cases a simple test implementation is sufficient and much easier
to understand and debug.
That said however, I do sometimes need to implement/mock just a few methods on a very wide interface and this is where
PartialStub helps. You can create an abstract class implementing just the methods you need for the test and use PartialStub
to construct it:
```java
public class PartialStubExampleTest {
@Test
public void testRowCount() {
TableModel partiallyImplemented = PartialStub.create(PartiallyImplementedTableModel.class);
assertEquals(3, partiallyImplemented.getRowCount());
}
}
public abstract class PartiallyImplementedTableModel implements TableModel {
@Override
public int getRowCount() {
return 3;
}
}
```
## FAQ
##### Why would I not just use an existing mocking framework to create a partial stub?
> You could, but then you are inviting your team to use every other feature of the framework (see intro above)