小编hub*_*hub的帖子

在C#中测试控制台进出控制台应用程序

我在C#控制台应用程序中测试"Console in"和"Console out"时遇到问题.

如果我使用Console.WriteLine和Console.ReadLine,我可以使用NUnit框架来测试应用程序,但如果我使用帮助程序类进入并输出到控制台,我无法使其工作.

帮助程序类是https://open.kattis.com/download/Kattio.cs并使用BufferedStream写入控制台,但我无法通过测试来阅读它...

它使用一个StreamReader作为"Console in",但我得到一个"NoMoreTokenException",我猜它没有得到任何输入......

我想使用帮助程序类但我不能用它测试...

例:测试用例:

    [Test]
    public void test_hello_world ()
    {
        using (var sw = new StringWriter ()) {              
            Console.SetOut (sw);
            using (var sr = new StringReader ("Start")) {
                Console.SetIn (sr);
                MainClass.Main(new string[]{});
                string expected = "Hello World!\n";
                Assert.AreEqual (sw.ToString (), expected);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

例如:有效的代码:

    string line = "";
    if (Console.ReadLine().Equals("Start"))
        line = "Hello World!";
    else
        line = "No such luck!";
    Console.WriteLine (line);
Run Code Online (Sandbox Code Playgroud)

例如:不起作用的代码:

        string line = "";
        Scanner sc = new Scanner …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing

4
推荐指数
1
解决办法
804
查看次数

removefromsuperview会删除子视图吗?

如果我有嵌套的子视图,如果我调用removefromsuperview,所有子视图都会被处理掉吗?

伪代码:

UIView *viewA = [[UIView alloc] initWithFrame:CGRectMake(0 , 0, 100, 100)];
[self.view addSubview:viewA];
UIView *viewB = [[UIView alloc] initWithFrame:CGRectMake(25 , 25, 50, 50)];
[viewA addSubview:viewB];
UIButton *buttonC = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[viewB addSubview:buttonC];
Run Code Online (Sandbox Code Playgroud)

然后按下buttonC:

[viewA removeFromSuperView];
Run Code Online (Sandbox Code Playgroud)

所有视图都会从屏幕上删除,但它们是否已正确删除?我是否需要手动删除所有视图?

objective-c ios ios6

2
推荐指数
1
解决办法
2247
查看次数

标签 统计

c# ×1

ios ×1

ios6 ×1

objective-c ×1

unit-testing ×1