如何运行并发单元测试?

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

如何使用junit执行并发测试?

How to use junit to run concurrency test?

假设我有一个类

public class MessageBoard { public synchronized void postMessage(String message) { .... } public void updateMessage(Long id, String message) { .... } }

我要同时测试对这个postMessage的多个访问。 对此有什么建议?我想对所有我的setter函数(或任何涉及create / update / delete操作的方法)运行这种并发测试。

I wan to test multiple access to this postMessage concurrently. Any advice on this? I wish to run this kind of concurrency test against all my setter functions (or any method that involves create/update/delete operation).

推荐答案

很遗憾,我不相信您可以通过运行时测试来确定您的代码是否是线程安全的。你可以抛出任意多的线程,因为它,它可能/可能不会通过,具体取决于调度。

Unfortunately I don't believe you can definitively prove that your code is thread-safe by using run-time testing. You can throw as many threads as you like against it, and it may/may not pass depending on the scheduling.

也许您应该查看一些静态分析工具,例如 PMD ,可以确定您如何使用同步和识别使用问题。

Perhaps you should look at some static analysis tools, such as PMD, that can determine how you're using synchronisation and identify usage problems.

更多推荐

如何运行并发单元测试?

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

发布评论

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

>www.elefans.com

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