我想在我的应用程序中开始进行更多的单元测试,但在我看来,我所做的大部分工作都不适合进行单元测试.我知道单元测试应该如何在教科书示例中起作用,但在现实世界的应用程序中它们似乎并没有多大用处.
我编写的一些应用程序具有非常简单的逻辑和与我无法控制的事物的复杂交互.例如,我想编写一个守护进程来响应某些应用程序发送的信号,并更改操作系统中的一些用户设置.我可以看到三个困难:
所有这些都可能是微妙的:我将不得不浏览可能复杂的API,我可能会引入错误,比如错误解释一些参数.单元测试能为我做什么?我可以模拟外部应用程序和操作系统,并检查给定来自应用程序的信号,我将在操作系统上调用适当的API方法.这是......嗯,应用程序的简单部分.
实际上我做的大多数事情涉及与数据库,文件系统或其他应用程序的交互,这些是最精细的部分.
再看另一个例子,看看我的构建工具PHPmake.我想重构它,因为它写得不是很好,但我担心这样做,因为我没有测试.所以我想补充一些.重点是单元测试可能无法捕获可能被重构破坏的东西:
glob,它与文件系统一起使用.如果我只是模拟一棵树代替实际的文件系统,glob将无法正常工作.我可以继续更多的例子,但重点是以下几点.除非我有一些精巧的算法,否则我所做的大部分工作都涉及与外部资源的交互,这不适合单元测试.更重要的是,通常这种互动实际上是非平凡的部分.仍有许多人将单元测试视为基本工具.我错过了什么?我怎样才能学会成为更好的测试人员?
使用<devenv>标签和<msbuild>标签之间的主要区别在于CruiseControl.NET?
我理解他们调用不同的可执行文件,但有时我得到不同的结果(在编译时通过/失败),我想知道为什么两个构建命令之间存在差异.
.net cruisecontrol.net continuous-integration visual-studio-2008 visual-studio
我想分配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) 我的应用程序中的菜单将包含太多要在单个垂直行中显示的项目.将它拆分为2个菜单看起来不是一个好的解决方案,因为它会破坏UI语义.我可以设置一个菜单以显示多列(如果垂直溢出,如Windows XP经典的开始菜单)?
我有一种偷偷摸摸的感觉,由于编译器,这可能是一个问题.
void SetRenderFunction(void (&newRenderFunction(void)));
这导致GCC宣称我"不能声明对'void'的引用"
现在,我在Windows上的Visual Studio下使用了相同的函数原型(或多或少).在Windows上我有一个不同的函数名称,而不是传递指向一个取消void的函数的指针,它指向我需要的其他一些对象.
如果我使用*而不是&它可以防止这个问题,但是当我尝试传入函数指针时,我会遇到类型转换问题:它试图将它void (*)()转换为void* (*)()
谢谢.
我正在编写一个套接字程序来下载图像.问题是,当我在像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) 我习惯于拥有垃圾收集器的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 …
SharePoint 2010搜索中的爬网程序影响规则和爬网规则之间有何区别?
我无法理解为什么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
}
}
}
}
更新宝石后我得到了这个:
/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) .net ×2
gcc ×2
iphone ×2
linux ×2
c ×1
c# ×1
c++ ×1
cashapelayer ×1
css ×1
html ×1
memory-leaks ×1
menustrip ×1
redcloth ×1
search ×1
sharepoint ×1
sockets ×1
uikit ×1
unit-testing ×1
winforms ×1
xamarin.ios ×1
yaml ×1