Programmers Only - Do you write unit tests first?

Page 1 of 1 [ 6 posts ] 


Do you usually write unit tests before tested code?
Yes 29%  29%  [ 2 ]
No 43%  43%  [ 3 ]
I'm a programmer but I don't understand the question 14%  14%  [ 1 ]
I'm not a programmer 14%  14%  [ 1 ]
Total votes : 7

MaxE
Veteran
Veteran

User avatar

Joined: 2 Sep 2013
Gender: Male
Posts: 1,492
Location: Mid-Atlantic US

16 May 2014, 5:02 pm

If you are a programmer you'll understand the question.



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 31
Gender: Male
Posts: 4,108
Location: Scandinavia

16 May 2014, 5:48 pm

I write unit tests during the code development if that's what you mean. On a large project, different people are working on different parts of the project. If I want to test that the data layer is working correctly before the business layer and the presentation layer is ready (or the business layer, if it's finished before the aforementioned) unit testing is really useful.

For unit- and integration testing, I use NUnit and FluentAssertions.


_________________
“He who controls the spice controls the universe.”


SammichEater
Veteran
Veteran

User avatar

Joined: 6 Mar 2011
Age: 26
Gender: Male
Posts: 3,903

16 May 2014, 6:41 pm

I've done a little programming and I have experience writing simple code, but I wouldn't consider myself a programmer. I have no idea what a unit test is. Would someone mind explaining it?


_________________
Remember, all atrocities begin in a sensible place.


MaxE
Veteran
Veteran

User avatar

Joined: 2 Sep 2013
Gender: Male
Posts: 1,492
Location: Mid-Atlantic US

16 May 2014, 7:36 pm

Kurgan wrote:
I write unit tests during the code development if that's what you mean. ....


Actually my question is more specific. Sorry my communication skills let me down*, but the poll asks about writing unit tests before writing the code to be tested. Namely the Test-Driven Development methodology in which you are supposed to write a test against phantom code then actually run the test and record the fact it failed on the first go so that everything after represents improvement.

Google TDD and you'll find numerous discussions on the topic.

*Theory of mind and all that.



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 31
Gender: Male
Posts: 4,108
Location: Scandinavia

16 May 2014, 8:50 pm

MaxE wrote:
Kurgan wrote:
I write unit tests during the code development if that's what you mean. ....


Actually my question is more specific. Sorry my communication skills let me down*, but the poll asks about writing unit tests before writing the code to be tested. Namely the Test-Driven Development methodology in which you are supposed to write a test against phantom code then actually run the test and record the fact it failed on the first go so that everything after represents improvement.

Google TDD and you'll find numerous discussions on the topic.

*Theory of mind and all that.


In early stages, I use test driven development. :)


_________________
“He who controls the spice controls the universe.”


beneficii
Veteran
Veteran

User avatar

Joined: 10 May 2005
Age: 36
Gender: Female
Posts: 7,193

16 May 2014, 11:22 pm

Yes, when I have a large project in mind, I usually test certain assumptions first for "proof-of-principle," which I think are basically unit tests. Like when I wrote the SMB3 Map Editor, the first thing I tested was loading the tiles, the palettes, and the sprites, along with using the tile maps specified in the game data and the Win32 API (SetDIBitsToDevice() was the function to actually draw the bitmap data on the window) to display World 1 of the game on a window. With that, I learned how to do a very important part of the program I needed to write and I showed myself I could make it work, and I started a new project with that in mind. Despite that, it took 3 attempts total (each attempt representing a separate project) to finally succeed in making the SMB3 Map Editor work.

It also occurs in smaller programs, where they aren't functioning as suspected. I start to dig through the code for any possibly erroneous assumptions I may be making about how, say, a library function call works, and then I do unit tests surrounding things like that library function call to test my assumptions--almost always in a separate project devoted just to tests. I find out where my assumptions are erroneous and then correct them, which results in the program working after much testing and debugging.


_________________
"You have a responsibility to consider all sides of a problem and a responsibility to make a judgment and a responsibility to care for all involved." --Ian Danskin