4

I myself have no idea of how to code, so am I able to perform unit testing?

Want answer in detail because I want to know how testers do unit testing.

8 Answers 8

15

The short answer - Usually they don't. Developers write unit tests and ideally run them every time the software builds.

The longer version - Unit tests are intended to test a single unit of code. This means that they are not testing through the application user interface, but are running directly against the single unit they are testing and using stub/mock data to simulate the unit's dependencies.

Because of this, no, someone with no coding knowledge can't write unit tests.

2
  • Just to clarify testers can write unit tests for testing libraries/frameworks they write.
    – dzieciou
    Sep 1, 2016 at 12:28
  • 1
    @dzieciou - obviously testers can write unit tests for their test code. I figured it was better not to add confusion, since the core of the question was whether someone with no coding knowledge could write them.
    – Kate Paulk
    Sep 1, 2016 at 15:36
3

Unit Testing is in my personal opinion the most difficult and important code a developer writes.

Unit Testing in it's core is breaking down the application into small pieces and ensuring that each piece is functional on it's own. It is an extremely cheap and easy way to ensure that sections are functional.

There is several different principles to Unit Testing. My personal favorite is Property Based Testing and BDD Tests.

As for can you write unit tests, no. You can't actually write them. You could review over the code, try and understand it and attempt to determine what should be tested and how. You could work with a developer and try and give them ideas for more unit tests. Writing them yourself as a QA is extremely difficult especially if you do not have write access to the AUT. And if the application is not currently being hit by unit tests it likely was not written with testing in mind which makes it 1000x harder to implement unit tests.

All of that being said one area where I feel QA should have more understanding is reviewing unit tests. A strong unit testing foundation drastically improves the timeline of the development process and results in a stronger project. It makes it easier and quicker for new developers to learn the application and requires developers to think about what they are implementing. Learn unit testing, study it and try and push your team to implement as many of them as makes sense to implement.

2

No, Unit testing only perform by the developers.

A unit is the smallest testable part of an application like functions, classes, procedures, interfaces. Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

Unit tests are basically written and executed by software developers to make sure that code meets its design and requirements behaves as expected.

7
  • 1 "the smallest testable part" - is this true?? Shailendra? 2 "source code are tested to determine if they are fit for use." Are you sure? Aug 30, 2016 at 11:34
  • 1
    This is probably the best answer here. Short, simple and accurate.
    – Paul Muir
    Aug 30, 2016 at 11:39
  • Yes agree with you paul. But do you really feel "the smallest testable part" & "source code are tested to determine if they are fit for use." are TRUE? According to me - "source code are tested to ensure if they are working as expected. Parameter generation and appropriate payload creation will be focused." Aug 30, 2016 at 11:45
  • 1
    @NarendraC this is accurate. A unit test should exercise only a single function/routine/method - "the smallest testable part". "determine if they are fit for use" means the same thing as "working as expected" - if the code is not working as expected it isn't fit for use.
    – Kate Paulk
    Aug 30, 2016 at 11:46
  • All are aligned then fine. Stronger the better! Aug 30, 2016 at 11:51
1

Unit test are just small programs which call small units of code being developed and test if the call returns expected values (or makes expected changes).

Unit testing is performed by program (which runs unit tests: test runner), not by a human.

So answer to your question is: no, someone with no programming skills by definition is not able to write unit test.

It also does not make sense for anyone else than a developer to write unit tests. To write them, you have to be extremely familiar with the minute details of the code, how code works from the inside. Only developers have such detailed knowledge (usually only of some parts of the whole system).

QA testers do not require such detailed knowledge of the code deep insides. They are focused on how different parts of the code fit together, and how they perform actions which user wants. It is very useful to perform such testing by someone who did not write the code, to flush out some unsaid assumptions.

Of course it is beneficial for a tester to have some knowledge of the system insides, so tester can better develop test strategies to test parts of the system which were not directly changed by a code path tested, but can be affected by the changes. But such knowledge is in more general terms, not on level of the detailed function calls and parameters passed.

1

There are some benefits of Unit Tests:

  • Developers have a fast feedback loop and know if something is broken immediately after they compile the code.
  • By writing the tests first, developers are forced to write classes with well defined responsibilities.

As you can see, testers instead of developers running Unit Tests gets rid of these benefits. To make it worse, giving testers control of Unit Tests introduces a rigid structure around the code that must be changed along with the code, but that the people in charge of the code have no control over.

Unit tests are run in 2 ways:

  • By the developer on the developer's machine
  • By the build system, as one of the final build steps.

This is not an either/or. If a tester gets a build, the Unit Tests have already passed.

1

I think testers should not test classes/modules/functions. testers should do functional testing and automate it. why? because programmers use their favorite language, tools, methodology. and those tools can change pretty frequently. code is constantly evolving and unit tests also have to evolve. programmers know how to correctly implement and refactor unit-tests to make their maintenance least expensive. programmers know which part of code is a public contract of their modules and which is only implementation detail (that usually should not be tested). programmers know on what parts of the system should be tested as a whole and which should be tested individually

to sum it up: maintenance of tests costs. in a healthy system there should be the biggest number of unit tests (rule of a thumb: up to 2x more lines of tests than production code). only programmers know how to make the maintenance cheap

however if you test system that suppose to talk with other system (rest, soap, etc) then it can be pretty close to unit-testing

0

Testers do not perform unit tests at all and I do not know any software development methodology, according which testers should do that. Only way, how the Tester, resp. a Test manager meets Unit testing could be (but does not have to), is to gather and report unit test results.

Some examples how methodologies consider Unit testing:

There could be a pressure to testing team to develop automated unit tests, but this is not generally supported and recommended by methodologies. I can imagine various problems which are on the way (as tester is not aware of the incoming changes, unit test are failing unless they are repaired, build never completely success because of deffered tests, etc.).

Some example of things, where somebody could think Unit tests belongs to testers:

  • For example in concept of Test driven development (TDD) of TMap NEXT testing mothodology, developers write tests of the Units first and after they do the code. But they are still developers and this will not make them testers of any kind. (read something about it here: http://tmap.net/wiki/test-driven-development)
0

Yes, but you will have to learn to code :) Programming is an awesome skill. Also a pretty helpful tool in your tester tool-kit.

If you want to learn unit-testing I would advice to start learning Test-Driven Development after you gathered basic coding knowledge.

Without having a lot of programming knowledge you could do pair-programming and assist in unit-testing then. Your pair can be the programming guru and you the test guru :)

There are four different roles in software development who do (unit)-testing:

  • Software Engineer: Writes most unit-tests

Writes a lot of test code including test driven design and unit tests.

  • Software Engineer in Test: Writes unit-tests when refactoring

A developer role except their focus is on testability. They review designs and look closely at code quality and risk. They refactor code to make it more testable. SETs write unit testing frameworks and automation.

  • Test Engineer: Doesn't write a lot of unit-tests, possible pairs with other roles during unit-testing

It is a a role that puts testing first and development second. Many Google TEs spend a good deal of their time writing code in the form of automation scripts and code that drives usage scenarios and even mimics a user.

  • Manual Tester: Doesn't write any automated tests.

Sources:

1
  • Test engeneer: should not write any UT and if he does, it is by methodological mistake. ;c) But agree with you, it could happen.
    – Dee
    Sep 1, 2016 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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