且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为这些类型的方法编写单元测试?

更新时间:2023-02-16 23:24:02

您已经问过有关单元测试"的问题,但您的问题似乎确实与原因有关:

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.