Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to make this library more test friendly? #316

Closed
davidxia opened this issue Nov 26, 2016 · 5 comments
Closed

Is there a way to make this library more test friendly? #316

davidxia opened this issue Nov 26, 2016 · 5 comments

Comments

@davidxia
Copy link
Contributor

davidxia commented Nov 26, 2016

Thanks for this library.

I'm trying to write unit tests that use objects like GHRepository, but I'm having a hard time creating a GHRepository instance with dummy data. There are no static constructors. It looks like the only way to create one with attributes is to deserialize from a JSON string with an ObjectMapper.

Can we make this library more test friendly?

@kohsuke
Copy link
Collaborator

kohsuke commented Nov 26, 2016

I'd use something like Mockito for that purpose. Are there some specific use cases where that doesn't work nicely? Constructors with attributes will go quickly out of control with a big object like GHRepository, and I hate making these objects mutable.

Another idea is to provide a HttpConnector that records & replays the HTTP calls into/from a file, which eliminates the need for a long & verbose mock object setups.

@davidxia
Copy link
Contributor Author

davidxia commented Nov 26, 2016 via email

@KostyaSha
Copy link
Contributor

@davidxia please let me know if you decide to make spotify/github-api

@kohsuke
Copy link
Collaborator

kohsuke commented Dec 17, 2016

@davidxia I'm not trying to claim that mock is perfect, but I don't see a big difference between mock vs static construction. In both cases, you'd have to construct an object graph with every attribute your business logic uses. And thinking about creating all the builders for each of the GH* classes make me dizzy.

That's why I suggested a replay at HTTP layers. That way, people writing tests will use actual captured JSON payloads, and I don't need to write all the builders.

@bitwiseman
Copy link
Member

Added WireMock facility working great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants