我正在使用Castle Windsor Typed Factory.在我们的注册码中,它被设置为可以创建一个Transient组件:
container.AddFacility<TypedFactoryFacility>();
container.Register(Component.For<IThingFactory>().AsFactory());
container.Register(Component.For<IThing>().ImplementedBy<TransientObject>().Named("TransientObject").LifeStyle.Transient);
Run Code Online (Sandbox Code Playgroud)
根据我对Castle Windsor Typed Factory文档的理解,我认为必须通过Typed Factory方法释放Transient对象,否则Typed Factory将保留对该对象的引用.我尝试通过编写使用此StackOverflow文章中解释的方法的测试来证明这一点.
但令我惊讶的是它实际上并没有失败,这意味着虽然我没有将瞬态物体释放回工厂,但它仍然可以被GC收回.我担心也许我的测试会产生误导,而且确实存在泄漏.
所以我的问题是:我的测试是错误的,还是文档错了?
这是测试:
var factory = container.Resolve<IThingFactory>();
WeakReference reference = null;
new Action(() =>
{
var service = factory.GetTransientObject();
reference = new WeakReference(service, true);
})();
GC.Collect();
GC.WaitForPendingFinalizers();
Assert.That(reference.Target, Is.Null, "reference should be null");
Run Code Online (Sandbox Code Playgroud) 我一直在使用SpecFlow进行验收测试.这使用Gherkin(DSL Cucumber使用).它包含一个名为"标签"的有趣功能.我可以看到它的实用性,但我不确定在BDD中使用标签可能构成什么样的好习惯.
我用谷歌搜索了一下,但不幸的是,包括"Tag"这个词与许多非Gherkin标签相匹配(就像这个页面上的那些!)
我希望在Cucumber维基上找到一些帮助,但标签主题尚未编写.
我发现声明"您可以使用标签将功能和方案分组,与您的文件和目录结构无关",但我恐怕不知道这意味着什么!
我有一个Cruise Control配置了一个任务来运行一个运行MSTest套件的NAnt脚本.MSTest允许我指定测试类别,因此我想指定"!Integration"(这意味着"不运行集成测试").当我从命令行运行它时,我的Nant脚本成功运行,但是当Cruise运行它时,"!Integration"指令出现乱码 - Cruise输出表明它在'!'之后插入一个换行符.字符.结果是我的所有测试都运行,包括集成测试.
从ccnet.config中提取:
<tasks>
<nant>
<executable>C:\nant\bin\nant.exe</executable>
<baseDirectory>C:\MyProject\BuildDirectory</baseDirectory>
<buildFile>MyProject.build</buildFile>
<targetList>
<target>CIServerBuild</target>
</targetList>
</nant>
</tasks>
Run Code Online (Sandbox Code Playgroud)
从MyProject.build中提取:
<target name="CIServerBuild">
:
<call target="RunUnitTests" />
</target>
<target name="RunUnitTests">
<property name="TestCategories" value="!Integration" />
<call target="RunMSTest" failonerror="true"/>
</target>
<target name="RunMSTest">
<call target="BuildListOfTestContainers" failonerror="true"/>
<exec program="${MSTest.exe}"
commandline=" /category:"${TestCategories}" ${TestContainers} /resultsfile:${MSTest.ResultsFile} /nologo "
/>
</target>
Run Code Online (Sandbox Code Playgroud)
从Cruise输出中提取:
[exec] Starting 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe ( /category:"!
Integration" /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Data.Tests\bin\Debug\TaxWise.Data.Tests.dll /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Domain.Tests\bin\Debug\TaxWise.Domain.Tests.dll /testcontainer:C:\TaxWise\BuildDirectory\TaxWise\TaxWise.Infrastructure.Tests\bin\Debug\TaxWise.Infrastructure.Tests.dll /resultsfile:.\TestResults\UnitTests.trx /nologo )'
in 'C:\TaxWise\BuildDirectory'
Run Code Online (Sandbox Code Playgroud)
我试过更换'!' 性格与
'!'
Run Code Online (Sandbox Code Playgroud)
但这没有任何区别.
任何想法,任何人?
我想扩展我的WatiN自动化测试以驱动一个页面,防止用户意外离开页面而不保存更改.
该页面使用"beforeunload"技术来寻求用户的确认:
$(window).bind('beforeunload', function (event) {
if (confirmationRequired) {
return "Sure??";
}
});
Run Code Online (Sandbox Code Playgroud)
我的WatIn测试是使用IE驱动页面.我找不到让WatIn附加到弹出对话框的方法,所以我可以从我的测试中控制它.
以下所有都失败了(硬编码字符串引用了我在弹出窗口中可以看到的字符串):
Browser.AttachTo<IE>(Find.ByTitle("Windows Internet Explorer");
browser.HtmlDialog(Find.FindByTitle("Windows Internet Explorer));
browser.HtmlDialog(Find.FindByTitle("Are you sure you want to leave this page?));
browser.HtmlDialog(Find.FindFirst());
Run Code Online (Sandbox Code Playgroud)
谢谢!
作为梅克的新手,我一直在进行一个测试来显示各种功能。但是,我无法理解为什么开发人员可能会调用 meck:validate。这是我的例子:
-module(meck_demo).
-include_lib("eunit/include/eunit.hrl").
validate_is_of_limited_use_test_() ->
{ foreach, fun setup_mock/0, fun cleanup_mock/1,
[fun validate_does_not_fail_if_a_function_is_not_called/0,
fun validate_does_not_fail_if_a_function_is_called_with_wrong_arity/0,
fun validate_does_not_fail_if_an_undefined_function_is_called/0,
fun validate_does_fail_if_a_function_was_called_with_wrong_argument_types/0,
fun validate_does_fail_if_expectation_throws_an_unexpected_exception/0 ]}.
validate_does_not_fail_if_a_function_is_not_called() ->
meck:expect(womble, name, fun() -> "Wellington" end),
?assert(meck:validate(womble)).
validate_does_not_fail_if_a_function_is_called_with_wrong_arity() ->
meck:expect(womble, name, fun() -> "Madame Cholet" end),
?assertError(undef, womble:name(unexpected_arg)),
?assert(meck:validate(womble)).
validate_does_not_fail_if_an_undefined_function_is_called() ->
?assertError(undef, womble:fly()),
?assert(meck:validate(womble)).
validate_does_fail_if_a_function_was_called_with_wrong_argument_types() ->
meck:expect(womble, jump, fun(Height) when Height < 1 ->
ok
end),
?assertError(function_clause, womble:jump(999)),
?assertNot(meck:validate(womble)).
validate_does_fail_if_expectation_throws_an_unexpected_exception() ->
meck:expect(womble, jump, fun(Height) -> 42 = Height end),
?assertError({badmatch, 999}, womble:jump(999)),
?assertNot(meck:validate(womble)).
setup_mock() -> …Run Code Online (Sandbox Code Playgroud) 我已经设法调整了我的SpecFlow测试的输出,以便它可以很好地读取,只需报告步骤和失败.但是,如果没有报告功能和场景名称,它仍然是不可读的.
查看生成的代码,看起来Feature和Scenario名称被编码为NUnit DescriptionAttributes.
我可以配置SpecFlow或NUnit来向stdout报告这些,所以我得到了一个非常流畅的"故事式"输出吗?