我正在使用MSTest框架编写集成测试.测试中的测试和代码都内置了重要的日志记录.
我试图找出一种方法来挂钩Assert的输出,这样我就可以将它与日志的其余部分一起写入日志文件.
例如,如果我有一个类似的测试方法
[TestMethod]
SomeRandomIntegrationTest()
{
//Code to actually run the test, and includes logging.
Assert.AreEqual(true, false, "This error message should also appear in the log");
}
Run Code Online (Sandbox Code Playgroud)
我会的
消息:Assert.AreEqual失败.预计是真的.得到了错误.此错误消息也应出现在日志中.
在我的日志文件中.
我试过了
private StringBuilder testOutputBuilder;
private StringWriter testOutputWriter;
private TextWriter originalWriter;
[TestInitialize]
public virtual void Initialize()
{
//Redirect the test output into the log files
testOutputBuilder = new StringBuilder();
testOutputWriter = new StringWriter(testOutputBuilder);
originalWriter = Console.Out;
Console.SetOut(testOutputWriter);
}
[TestCleanup]
public virtual void TestCleanup()
{
if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed)
{
//File logging …Run Code Online (Sandbox Code Playgroud) 如何TEST_IGNORE()在Visual Studio 2015中的本机VC++单元测试项目中使用宏?我习惯[Ignore]在C#中使用,但我显然在VC++中遗漏了一些东西.
这是我尝试过的,但TEST_IGNORE()宏扩展为无效代码(许多"意外令牌"和"语法错误:'{'"错误......)
TEST_CLASS(MyTests)
{
public:
TEST_IGNORE()
TEST_METHOD(TestSomething)
{
/*Test code is here*/
}
};
Run Code Online (Sandbox Code Playgroud)