如何将 StringBuilder 初始化为 null
大家好,我遇到了 StringBuilder
的问题。在自动化过程中,我会将 testfailed
的值分配给 StringBuilder
,因为
private StringBuilder testFailed = new StringBuilder();
public void Test1()
{
testFailed = SomeTest();
}
public void Test2()
{
testFailed = null;
//testFailed = testFailed.Clear();
//testFailed = new StringBuilder();
testFailed = someTest1();
}
当第一个测试失败时,testFailed StringBuilder
将附加下一个测试结果或者如果测试通过,则 testFailed
字符串将显示 testFailed b 结果值。当我使用注释方法并尝试时,它对此不起作用。让我知道任何其他方法。提前致谢。
Hi all I am facing a problem with StringBuilder
. While automating, I will assign the value of testfailed
to a StringBuilder
as
private StringBuilder testFailed = new StringBuilder();
public void Test1()
{
testFailed = SomeTest();
}
public void Test2()
{
testFailed = null;
//testFailed = testFailed.Clear();
//testFailed = new StringBuilder();
testFailed = someTest1();
}
When ever first test fails, the testFailed StringBuilder
will append the next test result or if test passes then testFailed
string will display the testFailed b result value. As I used commented methods and tried it didn't work for that. Let me know any other ways. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你想从中实现什么目标。但我猜您想汇总您正在运行的各种测试的错误。如果是这种情况,您不需要重新分配
StringBuilder
类,只需使用单个实例并对其使用Appends
,您的测试将返回字符串作为结果。例如。
我不知道你为什么采取这种方法,但每个人都有自己的方法。我还建议您看一下 NUnit。
I am not sure what you are trying to achieve from this. But I am guessing you want to aggregate the errors from various tests that you are running. If thats the case you dont need to reassign the
StringBuilder
class just use a single instance and useAppends
on it and your test will return string as a result.Eg.
I dont know why you are taking this approach, but to each his own. I would also suggest you take a look at NUnit.
请不要使用 null 作为值 - 这是一个坏主意。我会使用一个字符串列表来完成您正在做的事情。
Please don't use null as a value - it's a bad idea. I'd use a list of strings for what you are doing.