开发者

How to initialize a StringBuilder to null [closed]

开发者 https://www.devze.com 2023-03-23 19:12 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消