Have meaningful name in tests

Developers often take liberties when creating data in test files. It’s true, the data doesn’t matter.

Well, it doesn’t matter to machines, but it does to humans.

Just because it’s a test program doesn’t mean that you should create nonsensical names. Having meaningful names makes it easier to understand the business logic.

Here’s a snippet of code from a test file:

EmailLog.create_from_payload( to: [ 'qwe1@example.com',
                              from: ['support@example.com'])

I am not sure what qwe1 and qwe2 are supposed to mean here. It would be much better if the names were like the ones given below:

EmailLog.create_from_payload( to: [ 'mike@example.com',
                              from: ['support@example.com'])

Another example of a meaningful name

def test_email_is_normalized
  user = User.create! email: ' strAngeEmail@example.com'
  assert_equal 'strangeemail@example.com', user.email

In the above case, it is not clear why the email is strange. A better name would help.

def test_email_is_normalized
  user = User.create! email: ' thisIsAMixedCaseEmail@example.com'
  assert_equal 'thisisamixedcaseemail@example.com', user.email