te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How to appropriately reuse the describe blocks of mocha tests? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to appropriately reuse the describe blocks of mocha tests? - Stack Overflow

programmeradmin2浏览0评论

I have an app that runs in different modes (think of it as running for different platforms as well as using different protocols), one of which has a long loading period every time a page is opened. There are some other minor changes, but all of those could just be taken care of using wdio's setting variables.

Currently I have one test file (with a describe) for each section of the app. Which would be fine if one of the configurations being tested didn't have such a long wait time. Anyway, I've decided to deal with this test case, to handle it all in one file, which will all be on the same page.

Anyway, instead of copying and pasting all the tests I had previously to this one large file I was wondering if I could somehow reuse them, as if they were functions.

As it is right now I did just wrap things in functions, so for example:

// test1.js
module.exports = function test1 () {
  describe('Test1', function () {
    var settings = {}

    before(function () {
     // do something
    })

    it('do something', function () {
      assert.ok(true)
    })
    it('do something else', function () {
          assert.ok(true)
    })
  })
}

In another file we run every single function we created:

test1 = require('./test1')
test2 = require('./test2')
...
test10 = require('./test10')
describe('Main Test', function () {
  test1()
  test2()
  ...
  test10()
}

This would have solved my DRY problem, if I could somehow select which test functions to run upon my mand using

wdio wdio/wdio.conf.js --specs wdio/test/spects/browser/test1.js

Which obviously will not work.

Basically I want a solution to be able to reuse my tests (the describe blocks). Is what I was doing the right path? If not, how should it be done?

I have an app that runs in different modes (think of it as running for different platforms as well as using different protocols), one of which has a long loading period every time a page is opened. There are some other minor changes, but all of those could just be taken care of using wdio's setting variables.

Currently I have one test file (with a describe) for each section of the app. Which would be fine if one of the configurations being tested didn't have such a long wait time. Anyway, I've decided to deal with this test case, to handle it all in one file, which will all be on the same page.

Anyway, instead of copying and pasting all the tests I had previously to this one large file I was wondering if I could somehow reuse them, as if they were functions.

As it is right now I did just wrap things in functions, so for example:

// test1.js
module.exports = function test1 () {
  describe('Test1', function () {
    var settings = {}

    before(function () {
     // do something
    })

    it('do something', function () {
      assert.ok(true)
    })
    it('do something else', function () {
          assert.ok(true)
    })
  })
}

In another file we run every single function we created:

test1 = require('./test1')
test2 = require('./test2')
...
test10 = require('./test10')
describe('Main Test', function () {
  test1()
  test2()
  ...
  test10()
}

This would have solved my DRY problem, if I could somehow select which test functions to run upon my mand using

wdio wdio/wdio.conf.js --specs wdio/test/spects/browser/test1.js

Which obviously will not work.

Basically I want a solution to be able to reuse my tests (the describe blocks). Is what I was doing the right path? If not, how should it be done?

Share Improve this question asked Jul 27, 2017 at 18:19 theJulstheJuls 7,47018 gold badges96 silver badges182 bronze badges 1
  • Quite unclear what you mean by"one file on the same page". And the code does not show any code to share. – oligofren Commented Jul 29, 2017 at 7:05
Add a ment  | 

2 Answers 2

Reset to default 12

So I have figured out the best way to go about this after I found some documentation about it here.

I will just do as I previously described, however instead of shoving all those functions in the same file, I'll keep them in their own files. There still may be a better solution out there, but it is still an improvement from copying and pasting all test cases for the different modes of running my app.

Just programmatically create different describe blocks. Wrap the describe block in a function with all the parameters that change (including the name of the block) and simply invoke the function to create the variations.

I made a small repo to show this in practice: https://github./fatso83/forum-support-code/mit/cb2bc10b1d8bdae31e8f0a8c4e724c70583a5e11

发布评论

评论列表(0)

  1. 暂无评论