How do you unittest exceptions in Dart?

后端 未结 6 693
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 00:58

Consider a function that does some exception handling based on the arguments passed:

List range(start, stop) {
    i         


        
6条回答
  •  鱼传尺愫
    2020-12-09 01:41

    For simple exception testing, I prefer to use the static method API:

    Expect.throws(
      // test condition
      (){ 
        throw new Exception('code I expect to throw');
      },
      // exception object inspection
      (err) => err is Exception
    );
    

提交回复
热议问题