Dynamically creating tests

1,164 views
Skip to first unread message

Julien Genestoux

unread,
Jul 28, 2012, 5:30:29 AM7/28/12
to moc...@googlegroups.com
Hi!
We have a giant synchronous test suite: we run a bit of code on various inputs (more than 5000 XML feed files) and just check that the result matches the expectations (a JSON file of what the parsed feed should include). 
We are trying to run it thru mocha. This involves reading the XML files, the corresponding expectation from the JSON file and dynamically creating the `it` blocks.
Is there any way to do this? Based on what I see the `it` blocks cannot be defined dynamically. What am I missing?
thanks,


vision media [ Tj Holowaychuk ]

unread,
Jul 28, 2012, 12:33:34 PM7/28/12
to moc...@googlegroups.com
yeah you can dynamically generate stuff, I do it pretty often, things like
Message has been deleted

vision media [ Tj Holowaychuk ]

unread,
Dec 20, 2012, 11:34:35 AM12/20/12
to moc...@googlegroups.com
Ben if it's sync that will work just fine, but Mocha's tests must be set up before the first tick, then it runs. In the future we'll have a way to defer running with some (optional) manual mocha.run() on the server-end but for now they must be set up first, though in general I would question why this is even necessary, I've written hundreds of test suites and I've never needed this 

On Thu, Dec 20, 2012 at 7:55 AM, Ben Plessinger <b...@plessinger.us> wrote:
I tried to do this, but it never seems to work for me.

describe('Polling of async calls should work',function(){
    pollingPaths.forEach(function(path){
      it('Path: ' + path + ' should be accepted or complete');
    });
});

however this does not create the tests like I thought it should.

Ben Plessinger

unread,
Dec 20, 2012, 6:41:51 PM12/20/12
to moc...@googlegroups.com, t...@vision-media.ca
it is for an async api.

Adrien Lemaire

unread,
Feb 6, 2014, 10:07:58 PM2/6/14
to moc...@googlegroups.com, t...@vision-media.ca
Hi there,

I'd like to write dynamic tests a-la scenario outlines for cucumber.

Here is my test:

describe "Generic tests for all Cryptocurrencies", ->
  #it "generates a describe for each implemented coin", ->
    for coin in cryptoClassesList
      describe "Generic tests for #{coin}",
        it "has a code", ->
          coin.should.have.a.property "code"
        it "has a name", ->
          coin.should.have.a.property "name"
          coin.name.should.not.equal ""

my problem is that the **cryptoClassesList** dictionary is available only within a **it** function, not within **describe**. And if I create **describe** tests within a **it**, they are not run (wrong assertions pass).

Can one of those problems be solved ?
  • make cryptoClassesList available at describe level
  • Make describe built within a it discoverable and executable by mocha

As you can see in the code, the cryptoClassesList dictionary is built dynamically, one element added per file in the directory. So I cannot try to import the variable with a require before the describe, as I would need to know what is the latest file that added an element to the variable.

Thank you for your help

Kyan He

unread,
Sep 11, 2014, 11:57:53 AM9/11/14
to moc...@googlegroups.com, t...@vision-media.ca
Reply all
Reply to author
Forward
0 new messages