问题列表 - 第46278页

单元测试程序主要与外部资源交互

我想在我的应用程序中开始进行更多的单元测试,但在我看来,我所做的大部分工作都不适合进行单元测试.我知道单元测试应该如何在教科书示例中起作用,但在现实世界的应用程序中它们似乎并没有多大用处.

我编写的一些应用程序具有非常简单的逻辑和与我无法控制的事物的复杂交互.例如,我想编写一个守护进程来响应某些应用程序发送的信号,并更改操作系统中的一些用户设置.我可以看到三个困难:

  • 首先,我必须能够与应用程序进行交谈并获得有关其活动的通知;
  • 然后我需要在收到信号时与操作系统进行交互,以便更改相应的用户设置;
  • 最后所有这些应该作为一个守护进程.

所有这些都可能是微妙的:我将不得不浏览可能复杂的API,我可能会引入错误,比如错误解释一些参数.单元测试能为我做什么?我可以模拟外部应用程序和操作系统,并检查给定来自应用程序的信号,我将在操作系统上调用适当的API方法.这是......嗯,应用程序的简单部分.

实际上我做的大多数事情涉及与数据库,文件系统或其他应用程序的交互,这些是最精细的部分.

再看另一个例子,看看我的构建工具PHPmake.我想重构它,因为它写得不是很好,但我担心这样做,因为我没有测试.所以我想补充一些.重点是单元测试可能无法捕获可能被重构破坏的东西:

  • 要做的事情之一是决定要构建哪些内容以及哪些内容已经是最新的,这取决于上次修改文件的时间.当触发某些构建命令时,此时间实际上是由外部进程更改的.
  • 我想确保正确显示外部进程的输出.有时buikd命令需要一些输入,并且还应该正确管理.但我不知道先验流程将会运行 - 它可能是任何东西.
  • 一些逻辑涉及模式匹配,这似乎是可测试的部分.但是进行模式匹配的函数使用(除了他们自己的逻辑之外)PHP函数glob,它与文件系统一起使用.如果我只是模拟一棵树代替实际的文件系统,glob将无法正常工作.

我可以继续更多的例子,但重点是以下几点.除非我有一些精巧的算法,否则我所做的大部分工作都涉及与外部资源的交互,这不适合单元测试.更重要的是,通常这种互动实际上是非平凡的部分.仍有许多人将单元测试视为基本工具.我错过了什么?我怎样才能学会成为更好的测试人员?

unit-testing

20
推荐指数
1
解决办法
3201
查看次数

在CruiseControl.NET构建中使用'devenv'和'msbuild'有什么区别?

使用<devenv>标签和<msbuild>标签之间的主要区别在于CruiseControl.NET?

我理解他们调用不同的可执行文件,但有时我得到不同的结果(在编译时通过/失败),我想知道为什么两个构建命令之间存在差异.

.net cruisecontrol.net continuous-integration visual-studio-2008 visual-studio

11
推荐指数
3
解决办法
1万
查看次数

如何分配div 2显示属性?

我想分配div 2显示属性,我不确定正确的语法是什么...

#div2 {
  display:none;inline-block;
 }
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?

更新:

#div2 {
  display:none;
 }

$(function() {
  $("#div1").mouseover(function() {
    $("#div2").css('display', 'inline-block');
  }).mouseout(function(){
    $("#div2").css('display', 'none');
  });
});
Run Code Online (Sandbox Code Playgroud)

html css

4
推荐指数
1
解决办法
4317
查看次数

我可以将菜单拆分为WinForms中的多个列吗?

我的应用程序中的菜单将包含太多要在单个垂直行中显示的项目.将它拆分为2个菜单看起来不是一个好的解决方案,因为它会破坏UI语义.我可以设置一个菜单以显示多列(如果垂直溢出,如Windows XP经典的开始菜单)?

.net c# menustrip winforms

7
推荐指数
1
解决办法
1230
查看次数

提到无效

我有一种偷偷摸摸的感觉,由于编译器,这可能是一个问题.

void SetRenderFunction(void (&newRenderFunction(void)));

这导致GCC宣称我"不能声明对'void'的引用"

现在,我在Windows上的Visual Studio下使用了相同的函数原型(或多或少).在Windows上我有一个不同的函数名称,而不是传递指向一个取消void的函数的指针,它指向我需要的其他一些对象.

如果我使用*而不是&它可以防止这个问题,但是当我尝试传入函数指针时,我会遇到类型转换问题:它试图将它void (*)()转换为void* (*)()

谢谢.

c++ linux gcc function-pointers

1
推荐指数
1
解决办法
1549
查看次数

***glibc检测到***free():下一个大小无效(正常):0x0a03c978***

我正在编写一个套接字程序来下载图像.问题是,当我在像gif这样的小图片上测试我的代码时,它运行正常.但是当我使用JPG图片(大于GIF)运行它时,我收到了错误消息:

*** glibc detected *** /home/ubuntu/NetBeansProjects/myDownloader/dist/Debug/GNU-Linux-x86/mydownloader: free(): invalid next size (normal): 0x0a03c978 ***
Run Code Online (Sandbox Code Playgroud)

请查看代码,我将提供有关错误的更多信息.

FILE* pFile;
long lSize;
unsigned char* buffer;
size_t result;
FILE* combinedFile = fopen("mypic.jpg", "wb+");

for(i = 1; i <= numberOfPartitions; i++)
{
    sprintf(filename, "part%d", i);
    pFile = fopen(filename, "rb");

    //obtain file size
    fseek(pFile , 0 , SEEK_END);
    lSize = ftell(pFile);
    rewind(pFile);

    // allocate memory to contain the whole file:
    buffer = (unsigned char*) malloc(sizeof(unsigned char) * (lSize + 1));

    if(buffer == NULL)
    {
        fputs("Memory error", stderr); …
Run Code Online (Sandbox Code Playgroud)

c sockets linux gcc

6
推荐指数
1
解决办法
3万
查看次数

MonoTouch中的内存泄漏消息 - 我是否必须处理这些消息?

我习惯于拥有垃圾收集器的ASP.NET.然而,在进入MonoTouch和iPhone编程后,我在运行我的应用程序时发现了许多这些消息.

我是否忽略它们,还是应该在每个viewcontroller中实现某种卸载方法来处理对象?

当我将我的应用程序提交给iTunes时,这是苹果公司将要关注的事情(我还没有这样做)?

2011-02-12 20:58:55.641 wps[1200:7803] *** __NSAutoreleaseNoPool(): Object 0xfd34dd0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-02-12 20:58:55.648 wps[1200:7803] *** __NSAutoreleaseNoPool(): Object 0xfd3a710 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-02-12 20:58:55.649 wps[1200:7803] *** __NSAutoreleaseNoPool(): Object 0xfd3a830 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-02-12 20:58:55.650 wps[1200:7803] *** __NSAutoreleaseNoPool(): Object 0xfd3bae0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-02-12 …

iphone memory-leaks memory-management xamarin.ios

2
推荐指数
1
解决办法
987
查看次数

4
推荐指数
1
解决办法
4969
查看次数

CAShapeLayer hitTest touch

我无法理解为什么CAShapeLayer不响应hitTest

这个功能总是去//触摸外面

如何检测CAShapeLayer上的触摸?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{   

    currentPoint = [[touches anyObject] locationInView:self];

    for (CAShapeLayer *layer in self.layer.sublayers) {    

        if(layer == shapeLayer) {

            if([layer hitTest:currentPoint])
            {
                // touche is on the layer
            }
            else {
                // touche is outside
            }

        }

    }       

}

iphone core-graphics quartz-graphics uikit cashapelayer

1
推荐指数
1
解决办法
2284
查看次数

rails错误,无法解析YAML

更新宝石后我得到了这个:

/home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 182 column 9 (Psych::SyntaxError)
    from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
    from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:119:in `parse'
    from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:106:in `load'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth/formatters/latex.rb:6:in `<module:LATEX>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth/formatters/latex.rb:3:in `<top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth.rb:21:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth.rb:21:in `<top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/case_sensitive_require/RedCloth.rb:6:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/case_sensitive_require/RedCloth.rb:6:in `<top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `block in require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler.rb:120:in `require'
    from /home/megas/Work/railscasts/config/application.rb:10:in `<top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in …
Run Code Online (Sandbox Code Playgroud)

yaml redcloth ruby-on-rails-3

76
推荐指数
8
解决办法
8万
查看次数