Is it better if one person is responsible for writing tests and another for fulfilling them or should the coder and test writer be the same person, ideally?
Test cases are typically written by members of the quality assurance (QA) team or the testing team and can be used as step-by-step instructions for each system test. Testing begins once the development team has finished a system feature or set of features. A sequence or collection of test cases is called a test suite.
The unit tests should be written by the developer who writes the code, before she writes the code.
That's why developers should take some time out to write tests themselves. Finally, if developers write tests, it can save time by decreasing release issues, downtime of production, and the number of visible customer defects.
Less regressions, less frictions, less stress, more communications, all those are benefits of writing tests. Essentially you are a developer because you like to automate things. By writing tests you are actually automating a lot software development repetitive and tedious tasks.
Unit testing is something you do as you're writing code. This testing is testing your view how things should work (on the level of class/method/algorithm) and it supports you when developing as you can run through the tests before and after making changes to see that things are still according to the tests you have in place. See this as something that will aid the programmer as he/she works. Further, the tests will also provide a way to see how something is supposed to work for anyone looking at the code. TDD (Test-Driven Development) is not changing this concept, rather highlighting that the one coding needs to first think how it should work and what to expect.
If there is a problem with not seeing own problems one can try pair-programming, code reviews or other ways to look at things with more eyes and brains. Still I strongly believe unit testing is a tool for the programmer and not something done by anyone else.
Coming to other types of testing, like integration testing, functional testing or even (system) performance testing, it might be good to have other people doing this. Especially if you want to automate this testing it requires you to know how to do things and also maybe a higher level of business knowledge on what to test and how.
The answer to your question also depends on the culture and how your organization works, however, I believe you in all cases want to do unit testing as part of developing code. If this results in problems, there might be something else which is broken in the organization or something which needs to be looked at.
Update
Here are a few things I've seen in organizations which affect unit testing practices:
If there is an agreement to have unit testing, the above things might be issues to deal with in order to bring the organization into a state where things just work out naturally. If you have people with good unit testing practices and experience, let them lead things to bring the rest of the team to see the magic of unit testing.
Personally, I believe that if people see the benefits of unit testing, can write good unit tests, automate them with builds, and if the team can decide themselves how to organize how to get the unit tests written it will all fall naturally into place so that developers write unit tests while developing code, anyone can at any point add more unit tests for any code they're looking at. If there are testers, they would focus on other types of testing like functional testing or exploratory testing.
This question will invite many different answers, some based on how organisations work, some based on qualifications for planning and testing. There are many different ways to organise testing, especially since organisation sizes differ and may or may not have resources to hire different teams.
There are different types of testing:
In my experience:
Unit testing (atoms of functionality in isolation e.g. a single controller action) and Integration testing (those atoms working together e.g. a controller working with the domain tier objects, domain tier objects working with data tier objects,) should be done by the developer.
Functional testing (system functions as the spec states) should be done by a separate QA team.
Non-Functional testing can be done by a QA team or architect/tech lead.
UAT (system is fit for purpose) should be done by the client.
The reasoning behind this is, as automated Unit and Integration testing are white box (you can see inside the application e.g. the code), they will need to be completed by a developer (not neccessarily the developer responsible for the code under test).
Functional testing and UAT are black box (you can't see inside the application) so are more likely to be done by someone non-technical, but skilled in test analysis.
Non-functional testing can be either black or white box depending on what's under test and the overall strategy.
It's important to note that more defects are found by testing another's work than testing your own. The tester will think differently and so look for/try things that would not have been accounted for during development, and people are naturally protective of their code (no matter how hard one tries to be objective).
If there isn't a seperate test team, it's good to have developers test each others' code.
To answer your question a bit more, when I was a tester I was responsible for test analysis (deciding what functional tests were required to test the specs) and writing test scripts and manually executing them tests. Once those scripts were written, any tester could execute them, but it was important that the test analysis was done separately to the developer's work on the application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With