How to write unit test for these type of methods? [closed]

落花浮王杯 提交于 2020-04-17 21:30:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!