How to initialize a StringBuilder to null [closed]
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 t开发者_运维知识库estFailed 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.
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 use Appends
on it and your test will return string as a result.
Eg.
private StringBuilder testFailed;
public void Test1()
{
testFailed = new StringBuilder();
testFailed.AppendLine(SomeTest());
}
public void Test2()
{
testFailed = new StringBuilder();
testFailed.AppendLine(someTest1());
}
I dont know why you are taking this approach, but to each his own. I would also suggest you take a look at NUnit.
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.
精彩评论