我正在为我的应用程序的"粘合"层编写单元测试,并且很难为异步方法创建确定性测试,允许用户过早地取消操作.
具体来说,在一些异步方法中,我们有代码响应取消调用并确保对象在完成之前处于正确状态.我想确保测试涵盖这些代码路径.
在此场景中举例说明典型异步方法的一些C#伪代码如下:
public void FooAsync(CancellationToken token, Action<FooCompletedEventArgs> callback)
{
if (token.IsCancellationRequested) DoSomeCleanup0();
// Call the four helper methods, checking for cancellations in between each
Exception encounteredException;
try
{
MyDependency.DoExpensiveStuff1();
if (token.IsCancellationRequested) DoSomeCleanup1();
MyDependency.DoExpensiveStuff2();
if (token.IsCancellationRequested) DoSomeCleanup2();
MyDependency.DoExpensiveStuff3();
if (token.IsCancellationRequested) DoSomeCleanup3();
MyDependency.DoExpensiveStuff4();
if (token.IsCancellationRequested) DoSomeCleanup4();
}
catch (Exception e)
{
encounteredException = e;
}
if (!token.IsCancellationRequested)
{
var args = new FooCompletedEventArgs(a bunch of params);
callback(args);
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我提出的解决方案涉及模拟MyDependency
由胶层包裹的基础操作,并强制每个人在任意时间段内休眠.然后我调用异步方法,并告诉我的单元测试在取消异步请求之前休眠几毫秒.
像这样的东西(以Rhino Mocks为例):
[TestMethod]
public void FooAsyncTest_CancelAfter2()
{
// arrange …
Run Code Online (Sandbox Code Playgroud) 我已经看了一下ColorSpace类,并找到了常量TYPE_HLS
(可能只是HSL的顺序不同).
我可以使用此常量来创建Color
色调,饱和度和亮度吗?如果没有,是否有任何Java类,或者我需要编写自己的类?
序言:我知道,禁用警告不是一个好主意.无论如何,我对此有一个技术问题.
使用GCC 3.3.6,我收到以下警告:
choosing ... over ... because conversion sequence for the argument is better.
Run Code Online (Sandbox Code Playgroud)
现在,我想通过提供类似的参数来禁用此警告,如gcc警告选项中所述
-Wno-theNameOfTheWarning
Run Code Online (Sandbox Code Playgroud)
但我不知道警告的名称.如何找出禁用此警告的选项的名称?
我无法修复警告,因为它出现在无法更改的外部库的标头中.它在boost序列化(rx(s, count)
)中:
template<class Archive, class Container, class InputFunction, class R>
inline void load_collection(Archive & ar, Container &s)
{
s.clear();
// retrieve number of elements
collection_size_type count;
unsigned int item_version;
ar >> BOOST_SERIALIZATION_NVP(count);
if(3 < ar.get_library_version())
ar >> BOOST_SERIALIZATION_NVP(item_version);
else
item_version = 0;
R rx;
rx(s, count);
std::size_t c = count;
InputFunction ifunc;
while(c-- > 0){
ifunc(ar, s, …
Run Code Online (Sandbox Code Playgroud) 我想知道,一个参数是否可以在同一个查询中多次使用,如下所示:
MySqlParameter oPar0 = new MySqlParameter("e164", MySqlDbType.String);
oPar0.Value = user.E164;
string sSQL0 = "Delete from callmone.call where (caller=?e164 or called=?e164);";
clsDatabase.ExecuteSQL(sSQL0, oPar0);
Run Code Online (Sandbox Code Playgroud)
这是可能的还是我应该写2个参数?
当客户端使用TCP连接到服务器时,会为TCP流创建一个新套接字.连接是保留在连接的同一端口上还是更改为其他端口?
我正在尝试使用D2010 RTTI获取接口.
program rtti_sb_1;
{$APPTYPE CONSOLE}
{$M+}
uses
SysUtils,
Rtti,
mynamespace in 'mynamespace.pas';
var
ctx: TRttiContext;
RType: TRttiType;
MyClass: TMyIntfClass;
begin
ctx := TRttiContext.Create;
MyClass := TMyIntfClass.Create;
// This prints a list of all known types, including some interfaces.
// Unfortunately, IMyPrettyLittleInterface doesn't seem to be one of them.
for RType in ctx.GetTypes do
WriteLn(RType.Name);
// Finding the class implementing the interface is easy.
RType := ctx.FindType('mynamespace.TMyIntfClass');
// Finding the interface itself is not.
RType := ctx.FindType('mynamespace.IMyPrettyLittleInterface');
MyClass.Free;
ReadLn;
end. …
Run Code Online (Sandbox Code Playgroud) 我有两个div并排.我希望它们的高度相同,并且如果其中一个调整大小,则保持不变.虽然我无法想象这一点.想法?
为了澄清我令人困惑的问题,我希望两个盒子总是大小相同,所以如果因为文本被放入其中而增长,那么另一个应该增长以匹配高度.
<div style="overflow: hidden">
<div style="border:1px solid #cccccc; float:left; padding-bottom:1000px; margin-bottom:-1000px">
Some content!<br/>
Some content!<br/>
Some content!<br/>
Some content!<br/>
Some content!<br/>
</div>
<div style="border:1px solid #cccccc; float:left; padding-bottom:1000px; margin-bottom:-1000px">
Some content!
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果你有一个类接受一些参数但是不允许这些参数,那么最佳实践是null
什么?
以下是显而易见的,但例外有点不明确:
public class SomeClass
{
public SomeClass(Object one, Object two)
{
if (one == null || two == null)
{
throw new IllegalArgumentException("Parameters can't be null");
}
//...
}
}
Run Code Online (Sandbox Code Playgroud)
这里的异常让你知道哪个参数为null,但构造函数现在非常难看:
public class SomeClass
{
public SomeClass(Object one, Object two)
{
if (one == null)
{
throw new IllegalArgumentException("one can't be null");
}
if (two == null)
{
throw new IllegalArgumentException("two can't be null");
}
//...
}
Run Code Online (Sandbox Code Playgroud)
这里构造函数更整洁,但现在构造函数代码实际上不在构造函数中:
public class SomeClass
{
public SomeClass(Object one, Object two) …
Run Code Online (Sandbox Code Playgroud) 在过去一年左右的时间里,我的团队从1到5的增长相当快,并且非常有兴趣将我们的开发风格从瀑布改为像Scrum这样的迭代方法.我们为一所大学工作,专门为内部客户提供CRUD网络应用程序,他们总是在不断改变需求.
所以,我的问题是......我们如何最好地实施Scrum技术?
补充问题:是否建议退出瀑布"冷火鸡"以促进过渡或者您认为渐进式方法更有效?换句话说,选择一些scrum技术来实现,并在未来进一步添加其他技术?
我想从已经写入的日志文件中解析时间戳
datetime.datetime.now().strftime('%Y%m%d%H%M%S')
然后计算自此时间戳以来经过的秒数.
我知道我可以用它datetime.datetime.strptime
来取回一个datetime
物体,然后计算一个timedelta.问题是,该strptime
函数已经在Python 2.5中引入,我使用的是Python2.4.4(在我的上下文中无法进行升级).
有什么简单的方法吗?
java ×2
asynchronous ×1
c# ×1
c++ ×1
coding-style ×1
color-space ×1
constructor ×1
css ×1
css3 ×1
datetime ×1
delphi ×1
flexbox ×1
gcc ×1
hsl ×1
html ×1
html-table ×1
interface ×1
iteration ×1
mocking ×1
mysql ×1
null ×1
parameters ×1
parsing ×1
python ×1
python-2.4 ×1
rtti ×1
scrum ×1
tcp ×1
unit-testing ×1
waterfall ×1