The API docs for Test::More::ok is

ok($got eq $expected, $test_name);

right now in one of my apps I have $test_name print what the test is testing. So for example in one of my tests I have set this to 'filename exists'. What I realized after I got a bug report recently, and realized that the only time I ever see this message is when the test is failing, if the test is failing that means the file doesn't exist.

In your opinion, do you think these $test_name's should say what the test means if successful? what it means if it failed? or do you think it should say something else? please explain why?

closed as primarily opinion-based by Ixrec, user40980, durron597, gnat, GlenH7 Sep 5 '15 at 13:10

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.


I try to name my tests after the success case (C# syntax below).

public void BeginReviewPopulatesReviewer()
    Distribution = TestData.SubmittedToReviewerDistribution();

If I need to put a specific message to the console, I put the description of the failure:

Assert.IsNotNull(Distribution.CheckWire.Reviewer, "Reviewer is null.");
  • I would add that the message to be set should probably include the set of parameters that caused that particular failure. It's great to check the logs and spot that a test failed, but much easier if the reason is clearly laid out (although in your test, since it's a binary state, it's not really useful...) – Matthieu M. Jan 4 '11 at 19:54
  • My goal (not always met!) is to write each test so that there's only one reason for it to fail. – Marcie Jan 4 '11 at 19:55
  • I think that in Test::More this is really more of Description of failure, than the test name, even though the documentation says otherwise. in other words equivalent to where you put "reviewer is null" – xenoterracide Jan 6 '11 at 6:31
  • That sounds right to me. – Marcie Jan 6 '11 at 14:18

Following Roy Osherove's guidelines I use the three part naming convention Method_Setup_ExpectedOutcome. This would mean that the test name says what I expect a certain method to behave like under specified outcomes, i.e. the successful outcome of the test.

However, a lot of unit testing frameworks allow you to add additional messages to an assertion. That message will usually be displayed when the assertion fails. In this case I try to word the message to reflect what made this specific assertion fail.

So... for test names I go for the success case, in messages I go for the fail reason.

  • I think that in Test::More this is really more of Description of failure, than the test name, even though the documentation says otherwise. – xenoterracide Jan 5 '11 at 10:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.