我认为这些属性的全部目的是每个程序集只运行一次.我有一个简单的类如下:
[TestClass]
public class AssemblyIntegrationTestSetup
{
public AssemblyIntegrationTestSetup() { }
public TestContext TestContext { get; set; }
[AssemblyInitialize]
public static void SetupIntegrationTests(TestContext context)
{
WindowsServiceService.Instance.StartService("Distributed Transaction Coordinator");
}
[AssemblyCleanup]
public static void TeardownIntegrationTests()
{
WindowsServiceService.Instance.StopService("Distributed Transaction Coordinator");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行测试套件时,程序集级Initialize和Cleanup方法执行两次.以下是关于我的环境的详细信息:
观察到的行为类似于:
AssemblyInitialize
Class1.TestInitialize
Class1.TestMethod1
Class1.TestCleanup
AssemblyInitalize <-- //This shouldn't be happening right?
Class2.TestInitialize
Class2.TestMethod1
Class2.TestCleanup
Class2.TestInitialize
Class2.TestMethod2
Class2.TestCleanup
Class5.TestInitialize
Class5.TestMethod1
Class5.TestCleanup
Class7.TestInitialize
Class7.TestMethod1
Class7.TestCleanup
//More random bouncing around then...
AssemblyCleanup …Run Code Online (Sandbox Code Playgroud) 罗伊Osherove,作者的艺术单元测试,已经评论在博客上说的很多东西NUnit的所谓做更好,这是多快就是其中之一.
我的问题是,如果有的话,速度有多快?我们在谈论一个数量级吗?10%?50%?
我问这个是因为目前我无法比较这两者.我正在尝试将我的测试项目设置为双模式,以便我可以在它们之间切换.不幸的是,我遇到了NUnit与最新版本的Microsoft Moles集成的问题,并且NUnit与第三方库存在冲突(显示与log4net相关).
到目前为止,MSTest在Visual Studio 2008中似乎更容易使用.NUnit的所有版本问题和兼容性问题(至少对我来说)都指导我选择MSTest作为项目的框架(尽管我可能保持双模式)选项).MSTest的另一个优点是我仍然可以使用大多数NUnit断言:
using Assert = NUnit.Framework.Assert;
using Is = NUnit.Framework.Is;
Run Code Online (Sandbox Code Playgroud)
但是......如果在NUnit中速度确实快得多,那么我宁愿使用它,尽管有痛点.
最后,VS2010的MSTest速度是否有任何提升?
请考虑以下停止服务的方法:
Public Function StopService(ByVal serviceName As String, ByVal timeoutMilliseconds As Double) As Boolean
Try
Dim service As New ServiceController(serviceName)
Dim timeout As TimeSpan = TimeSpan.FromMilliseconds(timeoutMilliseconds)
service.[Stop]()
If timeoutMilliseconds <= 0 Then
service.WaitForStatus(ServiceControllerStatus.Stopped)
Else
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout)
End If
Return service.Status = ServiceControllerStatus.Stopped
Catch ex As Win32Exception
'error occured when accessing a system API'
Return False
Catch ex As TimeoutException
Return False
End Try
End Function
Run Code Online (Sandbox Code Playgroud)
为了对单元测试方法我基本上有两个选择:
ServiceController我需要的类的方法包装到我可以控制的接口中.然后可以将此接口注入服务类(也称为控制反转).这样我就可以使用松散耦合的代码,并可以使用传统的模拟框架进行测试.ServiceController以返回预设结果以进行测试.我同意对于使用"传统"单元测试方法的域模型代码最有意义,因为这会导致设计最容易维护.但是,对于处理与Windows API相关的东西(文件系统,服务等)的.net实现的代码,通过额外的工作获得"传统的"可测试代码是否真的有优势?
我很难看到将Microsoft Moles用于诸如ServiceController(或File对象)之类的东西的缺点.在这种情况下,我真的没有看到采用传统方法的任何优势.我错过了什么吗?
我正在使用vb.net/winforms.如何将包含三列的10行转换为DataSet/DataTable?
线条是这样的:
Item-1, $100, 44
Item-2, $42, 3
etc
Run Code Online (Sandbox Code Playgroud) 我想实现一个相当复杂的CurveEditor,它必须支持通常的要求,例如:

我不想操纵实际的WPF曲线,但是现有的带有键/值/切线的模型设置并从我们的实现中采样曲线的精确形状.
我已经收集了一些实现自定义UserControls和模板的经验.但我想确保,我不会错过任何明显的解决方案.我计划使用这个通用的XAML树:
我知道,这是一个非常复杂的问题,我不是要求实际实施.我对以下问题感兴趣:
我们正在为内部使用构建调查引擎.我想知道如何将问题分支逻辑保存到数据库中?以前做过这个的任何机构还是对数据库架构的任何想法?
如果用户回答了答案,我们需要根据添加到问题中的逻辑跳过下一个问题.每个问题都可以添加多个逻辑.
例如:
Question: Is it Sunny, Raining or Cloudy?
Answer: Raining.
The next question should be based on the previous answer.
if(Raining)
{
}
if(Sunny)
{
}
if(Cloudy)
{
}
Run Code Online (Sandbox Code Playgroud)
如何将上述内容保存到数据库并从那里开始?
有什么好主意吗?
我使用git-instaweb在我的本地机器上设置了一个git webserver.
现在我希望能够从那个回购中克隆,但是当我尝试时
git clone http://localhost:1234 它给了我一个错误:
fatal: http://localhost:1234/info/refs not found: did you run git update-server-info on the server?
Run Code Online (Sandbox Code Playgroud)
git update-server-info没有帮助.有人有解决方案吗?
先感谢您.
我有一个画布作为图像查看器.它的背景用于放置图像,我想在其上放置另一个图像.所以,场景是这样的:
<Canvas Name="VisorCanvas" Height="514" Width="720">
<Canvas.Background>
<ImageBrush />
</Canvas.Background>
<Image Name="foreground" />
</Canvas>
Run Code Online (Sandbox Code Playgroud)
我在后面的代码(C#)中动态插入图像.
问题是如果图像太大,那么图像会超出Canvas的边界.例如:我有一个不相关的背景图像,我想通过以下方式在Canvas面板(在其背景之上)显示一个正方形:
我该怎么办?我试过了:
如果有人能够阐明它,我将不胜感激.
考虑下面的代码(已经简化).我有一个服务类,它返回一个特定DTO对象的列表,每个对象都实现自己的特定接口.在实际代码中,当我使用遗留代码时,通过迭代数据集来填充这些代码.
问题:
我们如何创建/使用DTO而不用新增或使用Service Locator反模式?在Composition Root中组合一个空的DTO对象并通过构造函数将它注入Service类没有多大意义,因为我实际上在填充列表时使用DTO作为排序的临时变量.
在代码中,您可以看到我新建DTO的示例.但是,如果我首先让DTO不实现接口,这并没有好多少.那么,他们不应该实现接口,因此不使用DI与DTO?
public class Services : IServices
{
public IList<IDTO> GetDTOs()
{
...
List<IDTO> dtos = new List<IDTO>();
foreach (c in d)
{
DTO dto = new DTO();
dto.x = c.x;
dto.y = c.y;
dto.z = c.z;
dtos.Add(dto);
}
return dtos;
}
}
Run Code Online (Sandbox Code Playgroud) dependency-injection anti-patterns interface dto service-locator
免责声明:我很乐意在这个项目中使用依赖注入,并且全面地采用基于接口的松散耦合设计,但是在这个项目中使用了依赖注入.另外,SOLID设计原则(以及一般的设计模式)在我工作的地方是外国的,我自己也是很多人的新手.因此,在为此问题提出更好的设计时,请考虑到这一点.
这是我正在研究的代码的简化版本,因此它可能看起来很人为.如果是这样,我道歉.考虑以下类:
// Foo is a class that wraps underlying functionality from another
// assembly to create a simplified API. Think of this as a service layer class,
// a facade-like wrapper. It contains a helper class that is specific to
// foo. Other AbstractFoo implementations have their own helpers.
public class Foo : AbstractFoo
{
private readonly DefaultHelper helper;
public override DefaultHelper Helper { get { return helper; } }
public Foo() …Run Code Online (Sandbox Code Playgroud) unit-testing ×3
c# ×2
mstest ×2
vb.net ×2
wpf ×2
architecture ×1
branch ×1
canvas ×1
datatable ×1
dto ×1
git ×1
interface ×1
logic ×1
mocking ×1
nunit ×1
oop ×1
performance ×1
survey ×1
transparency ×1
xaml ×1