What would you include in Grock's 10-minute talk about unit testing

I will be doing a 10-minute talk with Grock at Unit Testing in my company soon. I tried it myself and I feel that it can benefit the company. We are already testing WebInject in our QA team, but I want to try and sell unit testing for developers.

So, just 10 minutes, what would you cover and why?

  • We are Microsoft Shop C # web applications, I have used NUnit in my experience.
+7
unit-testing theory
source share
15 answers

Unit testing is confidence .

This allows you to be sure that your code is solid and that other people can rely on it when they write their own parts of the system. If you can get through this testing, it will help to eliminate the thrill that comes with the first release of the new system, I hope that your audience will soon become very interested.

+15
source share

I would start with a problem that many programmers can become familiar with: it is a fear of making changes to existing code because of the fear that they might break something. How does this prevent the work or prevent its proper execution (because they are afraid of refactoring), and therefore leads to the need to rewrite everything every x years.

Testing devices → Refactoring → Live code.

Edit: By the way, I would not quote “all code without unit tests is legacy code” from Michael Persa. The first time I heard this, I felt defensive. By the time people stop feeling offended, 10 minutes will end :-) (personally, I think the quote is more correct than useful).

+8
source share

Here's a good format for a short conversation on X technique:

  • why you decided to try it in the first place.
  • what you personally got from using X
  • what restrictions did you notice that X does not address

Do not “sell” or spend a lot of time on theory. Do in advance and point people to books, URLs for articles or manuals that you think are most useful. Those who are interested in your conversation can find information on the Internet.

+4
source share

Try to briefly talk about the aspect of Test Driven Development: write tests and interfaces first, and then implement everything.

Perhaps also about continuous integration, this means that as soon as you check something in your original control system, the project will compile and all the tests will run, so the developer will immediately know that he did something wrong.

If there are any project managers in the audience, also be so fair as to tell them that unit testing will make your project 15-30% longer, but it will cost in the end.

+3
source share

You might mention that this will be a complex learning curve, and the impact of productivity on productivity will be felt, but the benefits are:

eg. effectively creating a set of automatic regression tests, which, in turn, allows you to make large additions or modifications to existing ones without worrying that you are violating some existing functions.

Creating production code will be slower, but this should be offset by a higher quality code, i.e. fewer errors, which ultimately means overall performance.

+2
source share

Accountability , as Kent Beck emphasized, is another sign that facilitates unit testing. Listen to his podcast on IT conversations . (His point of view on reporting starts at 30:34.)

+1
source share

I think 10 minutes is enough to provide a simple example of how unit testing can save you time.

Implement a class (you can use TDD if you like it) and show how unit test can catch a modification that breaks the class.

In addition, you can specify how you can develop components faster if you test in isolation (i.e. you do not need to raise your web application, log in, go to your functionality, test); you can just run your tests.

You may be able to do this on a piece of code from your company, and perhaps show how unit test could detect an error that you recently encountered.

+1
source share

If you give a demo, do it on a working piece of code from a project that everyone is familiar with. Avoid far-fetched examples. Books on TDDs are already full of them, and they really don't sell how TDD can work for a real project.

+1
source share

For love of God, emphasize that unit tests are designed to test logic “units”. I don’t like to watch the NUnit QA test suite that no one expected to support, where each “unit test” checks the valid outputs for 150 (binary) input files, and then it gets corrupted if one fails without telling you which one .

+1
source share

I would demonstrate:

  • The confidence that it gives in the code that you produce
  • The trust that it gives when changing code, as it passes unit tests
  • Benefits of code coverage, no more "Oh, this other statement has never been tested!"
  • Benefits of running unit tests for each build on a CI platform such as Hudson

FWIW we run a crappy visual studio check through MSTEST in our Hudson box, and I have xslt that uses Hudson to convert the results to nunit so that Hudson can decrypt them. Just put it there if they want you to stick with the Microsoft testing platform.

+1
source share

From a business perspective, you may need to emphasize the fact that unit tests can “deactivate” any changes you make to your code. After you have a set of unit tests, you can make changes to the code base and find out what breaks and what does not.

Perhaps I will not be bad at testing users. If you have a good set of tests, you can bring unsuccessful tests to users after making changes so that they confirm the correctness of the new results. In addition, you can optimize the collection of requirements if you have users writing new unit test definitions for you. They should not be able to code, but they should be able to give you the appropriate input and expected results (otherwise, how do they know if the changes they requested work?).

Visual Studio has a pretty good set of unit testing tools, so an example or two can greatly help give your group an idea of ​​what unit testing is in practice.

0
source share

Wear this t-shirt ; -)

0
source share

Well-prepared demo version:

  • Find the "error" in your "application"
  • Write a unit test that covers this error.
  • Fix this error
  • Show your code is green.

So, you can prove that there is no way for this error to happen again!

0
source share

Another way to do this:

Suggest a problem that can be solved by creating an algorithm. Something relatively simple, of course. Then, code this algorithm in a DLL project. Try to get into some flaws (i <= array.Length is always good). Then ask them how they will test this DLL.

Most developers run their testing applications. But you can not start the DLL. You might suggest creating a console application to create methods that implement the algorithm. Show them how you can create unit tests for this.

0
source share

You have a good set of resources for further / independent training:

  • pragmatic unit test for java / C # - good books on the topic
  • kent beck paper for unit testing
  • links to any larger samples using a selection to select.
0
source share

All Articles