由于 PHPUnit 中的 hook 方法出错而跳过测试

Test skipped because of an error in hook method in PHPUnit

当 运行 PHPUnit 时,一些测试被跳过并显示消息 'Test skipped because of an error in hook method'。是什么原因造成的?如何防止测试被跳过?

PHPUnit 中的测试可以有一些称为挂钩的魔法方法。这些由 PHPUnit 自动调用。这些方法是:

  • 设置()
  • 拆解()
  • setUpBeforeClass()
  • tearDownAfterClass()
  • onNotSuccessfulTest()

任何这些方法中的错误都将导致测试被跳过并出现错误 'Test skipped because of an error in hook method'。为防止测试被跳过,请检查每个方法以找出错误并修复它。