RETRY TESTS

Mocha允许你为失败的测试用例指定需要重复的次数。这个功能是为端对端测试所设计的,因为这些测试的数据不好模拟。Mocha不推荐在单元测试中使用这个功能。

这个功能会重新运行beforeEach/afterEach钩子,但不会重新运行before/after钩子。

下面是一个使用Selenium webdriver写的一个重复执行的测试用例。

  1. describe('retries', function () {
  2. // 尝试全部的失败的测试4次,
  3. this.retries(4);
  4. beforeEach(function () {
  5. browser.get('http://www.yahoo.com');
  6. });
  7. it('should succeed on the 3rd try', function () {
  8. // Specify this test to only retry up to 2 times
  9. this.retries(2);
  10. expect($('.foo').isDisplayed()).to.eventually.be.true;
  11. });
  12. })