lundi 27 juin 2016

Is there exists any tool for generating a JavaScript Unit test from spying in on running code, say in browser?

I understand that taking time and thinking to write tests with proper assumptions is important. However something like this can serve as starting boilerplate code.
For example , consider a function

function sum(a,b) {
  return a+b;
}
console.log(sum(3,4,5));
console.log(sum(0,2));

so we inject/include a function , i.e it listens
in on the input given to sum while it is running(like dojo connect) and auto generates the test cases.

so the tool will automatically generate tests as

describe("sum tests", function(){
    SpyOn(sum);
    expect(sum(3,4,5).to.Equal(12));
    expect(sum(0,1).to.Equal(1))
})

If something like this doesn't exist , I was thinking to attempt to build a basic version of this myself. I guess for complex inputs as objects ,may need to create spies for function call. ex -

sum.apply(null, Source.getInputs()).

so now need to mock the Source.getInputs function. What other complications I may need to take into account in that case ?

Aucun commentaire:

Enregistrer un commentaire