java - 运行整个课程时如何跳过一种方法到另一种方法?
问题描述
我尝试在一个类下测试几个测试,例如我需要测试三个测试
testA()
,<code>testB()、<code>testC()
问题是如果在测试期间出错,我可以跳过testA()
并继续执行任何代码吗?testB()
testA()
我试过system.exit(1)
了,但它会阻止整个班级
解决方案
您可以使用:
try{
//if there is any error here, it will skip and will be caught by the catch block
testA()
} catch (Exception e){
//handle your exception here
testB()
}
签出:Try-catch
用于异常处理
推荐阅读
- javascript - Javascript - 将函数作为参数传递
- c# - VS Designer 现在显示 MainMenu
- swagger-ui - SwaggerUIBundle 和 SwaggerUi 有什么区别
- node.js - 使用 node.js http2 模块的服务器发送事件 - 我应该如何将它与流 / pushStream 一起使用?
- azure-service-fabric - 为 Service Fabric 本地群集启用 ResourceMonitorService 插件失败
- awk - 用 awk 替换大写或小写的字符串
- json - Ionic App 在 Android 设备上无法正常工作
- apache-kafka - 为什么这个 KStream/KTable 拓扑会传播未通过过滤器的记录?
- javascript - .diff 不是 Moment.js 中的函数
- c# - 通过 Twilio C# 库发出呼叫或短信请求是否总是使用 HTTPS?