-
Notifications
You must be signed in to change notification settings - Fork 8
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
Library does not lend itself to unit testing #30
Comments
Pull requests are welcome! |
So I've reviewed this question, and the companion pull request, and I have some observations. In the example test provided above, it appears as if two questions are under consideration:
The first area under test seems better suited to an integration test with appropriate test data. My thinking here stems from the structure of that part of the test. If you notice, it looks like the mocking framework is being exercised and not application logic. In this case, an integration test would allow you to validate that the graph query defined is syntactically correct and returns an expected result set which would obviate the need for the second area of the unit test (which is more of an assertion of the implementation rather than a test of logic). With all of that said, I really appreciate your contribution but I don't think the suggested changes are appropriate for this library. Cheers, Tom |
I agree that this absolutely would work better as a low-level integration test - that would in fact be my normal way to test a repository like this. However, in this particular circumstance, that isn't an option. The particulars of the test aside, the fact that the library is not abstractable makes unit testing anything that uses it very difficult. So even if I wasn't going to test graph directly as I do in my example test, because I cannot inject/abstract RedisGraph (without wrapping it in my own adapter/factory, as I have done as a mitigating measure), the entire class becomes untestable, which is simply a bad architecture. Ultimately, it's your choice, as it's your library/package and therefore your architecture. I appreciate the time you've spent looking at it. |
I am attempting to implement unit tests of a repository that uses NRedisGraph to access my Redis data. As one should always do for unit testing, I am mocking/faking al ldependencies, which includes objects from NRedisGraph. However, the library is too hard-coded and makes this impossible:
new
command (no abstract factory, no interface for dependency injection, etc.), I had to wrap the graph object in an adapter so that it would be unit testable.ResultSet
from the graph object's QueryAsync function. However, this object is sealed and internal. However, since it implementsIEnumerable<Record>
, I could create that enumerable and cast it toResultSet
when needed. Further cumbersome, but at least doable.Record
are all internal, so I cannot instantiate a new one when setting up my mocks in my test. The class is sealed, which means I cannot extend it. It implements no interfaces and isn't abstract, so I can't mock it directly. This means that I cannot, in any way, shape, or form, create aRecord
object in a unit-test appropriate way. Therefore, all the other earlier work is for naught.Ideally, we would have interfaces for the RedisGraph object, so it can be mockable at the root. Barring that, there needs to at least be 1 public constructor for the
Record
object, so they can be instantiated for mocks in a unit test.Below is an example of my test:
The text was updated successfully, but these errors were encountered: