如何为这些类型的方法编写单元测试? [英] How to write unit test for these type of methods?
问题描述
我是单元测试的新手.如何为这些类型的方法编写单元测试?
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;
}
此处Vertex是gremlin查询的元素. 我试图创建图的实例并将新的Vertex对象传递给该函数,但不起作用. 即
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?
推荐答案
您已经问过有关单元测试"的问题,但您的问题似乎确实与原因有关:
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");
不允许您创建可以测试的Vertex
.我想说的最明显的问题是,您没有
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();
当然,对于要测试的fn(Vertex)
函数,在图形数据库中创建实际的Vertex
并没有多大意义-您可以只使用org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex
并执行以下操作:>
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.
这篇关于如何为这些类型的方法编写单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!