login about faq

What conventions do you use to name your test classes and unit tests?

asked Dec 03 '09 at 01:40

leypascua's gravatar image

leypascua
1.6k115


I'm not saying this because it's "best practice" or so, but it works for me. Usually when I'm in the early stages of coding I have simple tests (unit tests!) that test only a specific class. So most likely I have one test per class. So if my class name is "FileReader" I have a test class named "FileReaderTest." Then each method of my test class would test a particular functionality or behaviour of the class. I kinda name my tests with a "Should" -- similar to BDD. So it says "ShouldOpenFile" or "ShouldThrowExceptionIfFileNotFound" etc. I stick to CamelCase because that's how .NET code generally looks like. If I use ruby_case or some other convention, my code will stick out like a sore thumb and probably drive other developers in my team away.

link

answered Dec 03 '09 at 10:21

cruizer's gravatar image

cruizer
1.5k9

I prefer using ruby case because my eye hurts when reading long camel cased method names. And because many of the devs in the team don't write proper unit tests either way, it's not really an issue.

(Dec 11 '09 at 05:29) Jon Limjap Jon%20Limjap's gravatar image

Well it depends on what language you are using but basically if you have a class named Person you usually name your test class (unit or integration tests) as PersonTest or TestPerson but the former is well-recommended.

link

answered Dec 10 '09 at 19:08

bobsantos's gravatar image

bobsantos
3665

1

Oh I just realized that cruizer has an example already. Must be tired.. but again you may want to look for specific conventions for the language you are using.

(Dec 10 '09 at 19:11) bobsantos bobsantos's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×31
×6
×1

Asked: Dec 03 '09 at 01:40

Seen: 621 times

Last updated: Dec 10 '09 at 19:08