mardi 8 décembre 2020

mocha - writing tests - should I remember the previous results?

I wrote some tests in mocha.

the code is gonna look like this.

describe('contract', accounts => {
  it("test1", () => {

  })


  it("test2", () => {
    
  })

  it("test3", () => {
    
  })
  
})

Now, let's say I call function1 in test1 and check if everything is correct after calling function1. Then, In test2, I test function2, but function2 is kind of dependent on test1's function1's changes. Then, in test3, I test function3, which is kind of dependent on function2's changes. So it's like test3 needs to know the state of my variables that function2 did in test2 and test2 needs to know the state of my variables that test1's function1 did.

Problem 1: If I leave it like the above, the problem is that, when another developer comes, he won't be able to quickly change something in test3 , because if he does, then he needs to know what to change in test2 too which means he needs to know what he needs to change in test1. This doesn't seem scalable.

Problem 2: Another solution would be that I have one single test case and include all these dependent functions in single test, But now, the problem is that I'd need 3-4 tests like this, since to test each path. and each test would have lots of calls/codes. I'd prefer that each test would test each function.

What do you think ? any advice you could give me ?

Thanks..

Aucun commentaire:

Enregistrer un commentaire