布尔型Pop()方法,带有要检入MSTest的异常 [英] Boolean Pop() method with exception to check in MSTest

查看:81
本文介绍了布尔型Pop()方法,带有要检入MSTest的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用MSTest并对其进行了解.我的问题是,我尝试这样做是一个例外.引发异常时,应用程序应关闭.但是,然后我无法使用布尔方法测试我的程序.有办法解决吗?

So im using MSTest and learning about it. My Problem is, that i am trying to do is give a exception. When the exception is thrown the application should Close. But then i cant test my program with a Boolean Method. Is there a way around this?

public bool Pop()
        {             
                Node temp = Head;

                if (CountPosition > 0)
                {
                    CountPosition--;
                    temp.Data = null;
                    Head = temp.Next;

                    //return true;
                }            
            if (CountPosition == 0)
            {
                
                if (temp == null)
                {
                     
                    throw new IOException();
                           
                }              
                
            }  
            //return false;
   
              
        }

这是我简单的异常方法

public class IOException : Exception   
    {       
        public IOException()
        {            
            
           
        }
        public void ErrorMessage()
        {
            Console.WriteLine("Pop() was used in a Empty stack");
            Console.WriteLine("Please Try Again");
            Console.WriteLine("Closing the Program");            
            Console.ReadLine();

        }
    }

推荐答案

这是我的测试方法

here is my test method by the way

[TestMethod]
        public void BasicPop_1_Input()
        {         
                         
              
            StackLinkedList.List MyList = new StackLinkedList.List();
                        
             bool test = MyList.Pop();
            


            Assert.AreEqual(false,test);

        }


这篇关于布尔型Pop()方法,带有要检入MSTest的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆