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

编程入门 行业动态 更新时间:2024-10-23 08:25:39
本文介绍了如何为这些类型的方法编写单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是单元测试的新手.如何为这些类型的方法编写单元测试?

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.我想说的最明显的问题是,您没有以任何方式重复遍历.在这种情况下,您需要致电next():

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.

更多推荐

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

本文发布于:2023-11-15 13:50:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1595005.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:何为   单元测试   类型   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!