单元测试CTRL-C发送到应用程序 [英] unit testing for CTRL-C sent to an application

查看:86
本文介绍了单元测试CTRL-C发送到应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个处理CTRL-C的应用程序。我生成一个信号处理程序来关闭线程和其他资源。



我想在我的应用程序可能在不同的情况下测试CTRL-C。我知道如何为被测试的进程设置这些,但我需要一种方法(在运行测试套件的代码中)来检查是否达到该条件才能正确调用CTRL-C。



我在Linux中工作,我想在 CPPUNIT 的帮助下自动运行测试。在我的每个CTRL-C测试中,我启动进程,然后使用具有进程PID的 kill 函数发送CTRL-C。



我使用共享内存;一旦测试的应用程序达到我感兴趣的条件或当我想发送CTRL-C的点,我写一个标签或状态到共享内存。同时,在不同的进程中运行的测试套件代码是连续轮询共享内存,一旦它读取它发送的CTRL-C / kill所需的状态。



Do你认为是一个好的方法,或者它通常是以更好/有效的方式完成?



种类问题



AFG

解决方案

首先测试接收到一些外部信号时的行为看起来不像单元测试,但是像功能测试。



此外,你这样做的方式听起来太复杂,可能会强制某种同步并隐藏一些行为。



另一方面,我真的没有什么更好的建议这种测试,这通常是由外部工具以更少的控制方式。 p>

I am developing an application handling CTRL-C. I am producing a signal handler to shut-down gracefully threads and other resources.

I want to test CTRL-C in different scenarios where my application might be. I know how to setup those for the process under test, but I need a way ( in the code of the running test suite ) to check whether that condition is reached or not to call exactly CTRL-C.

I work in Linux and I want to run my tests automatically with the help of CPPUNIT. In each of my CTRL-C tests I start the process and then I send CTRL-C using kill function having the PID of the process.

I am using shared memory; once the tested application reaches a condition of my interest or a point when I would like to send CTRL-C , I write a tag or a state into the shared memory. Aat the same time the test suite code running in a different process is continuosly polling the shared memory and once it reads the desired state it send CTRL-C/kill.

Do you think is a good approach or it is usually done in better/effective ways?

Kind Regards

AFG

解决方案

First testing the behavior when some external signal is received does not look like unit testing but like functional testing.

Also, the way you do it also sound too complicated and is likely force some kind of synchronization and hide some behaviors.

On the other hand I do not really have something better to suggest for this kind of tests, this is usually done by external tools in a much less controled way.

这篇关于单元测试CTRL-C发送到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆