mardi 20 février 2018

How to implement BDD practices with standard Go testing package?

I want to write tests first, then write code that makes the tests pass.

I can write tests functions like this:

func TestCheckPassword(t *testing.T) {
    isCorrect := CheckPasswordHash("test", "$2a$14$rz.gZgh9CHhXQEfLfuSeRuRrR5uraTqLChRW7/Il62KNOQI9vjO2S")

    if isCorrect != true {
        t.Errorf("Password is wrong")
    }
}

But I'd like to have more descriptive information for each test function.

For example, I am thinking about creating auth module for my app. Now, in plain English, I can easily describe my requirements for this module:

  1. It should accept a non-empty string as input.
  2. String must be from 6 to 48 characters long.
  3. Function should return true if password string fits provided hash string and false if not.

What's the way to put this information that is understandable by a non-tech business person into tests besides putting them into comments?

Aucun commentaire:

Enregistrer un commentaire