问题
I'm new to unit testing . How to write unit test for these type of methods?
private boolean fn(Vertex vertex) {
return vertex.id().toString().split(":").length > 1;
}
Here Vertex is the element of gremlin query . I have tried to create instance of graph and pass a new Vertex object to the function but not working . i.e
Vertex vertex = (Vertex) graphTraversalSource.addV("Test").property(id,"Profile:TEST");
Can anyone suggest the ways to test these types of method?
回答1:
You've asked your question about "unit testing" but your question really seems to be about why:
Vertex vertex = (Vertex) graphTraversalSource.addV("Test").property(id,"Profile:TEST");
doesn't let you create a Vertex
that you can test. I'd say the most obvious problem is that you didn't iterate your traversal in any way. In this case you need to call next()
:
Vertex vertex = (Vertex) graphTraversalSource.addV("Test").property(id,"Profile:TEST").next();
Of course, for your fn(Vertex)
function that you want to test, I don't see much point in creating an actual Vertex
in a graph database - you could instead just use org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex
and do:
Vertex vertex = new DetachedVertex("Profile:TEST", "Test", null);
and then pass that to your function to test.
来源:https://stackoverflow.com/questions/61154074/how-to-write-unit-test-for-these-type-of-methods