Understanding how software testing works and what to test

General Tech QA/Testing . 2 years ago

  0   2   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 5 Rating

Posted on 16 Aug 2022, this text provides information on QA/Testing related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Write Your Comments or Explanations to Help Others



Tuteehub forum answer Answers (2)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

Intro: 
I've seen lots of topics here on SO about software testing and other terms I don't understand.

Problem: 
As a beginner developer I, unfortunately, have no idea how software testing works, not even how to test a simple function. This is a shame, but thats the truth. I also hope this question can help others beginners developers too.

Question: 
Can you help me to understand this subject a little bit more?

Maybe some questions to start would help:

  • When I develop a function, how should I test it? For example: when working with a sum function, should I test every input value possible or just some limits? How about testing functions with strings as parameters?
  • In a big program, do I have to test every single piece of code of it? When you guys program do you test every code written?
  • How automated test works and how can I try one? How tools for automated testing works and what they do?
  • I`ve heard about unit testing. Can I have a brief explanation on this?
  • What is a testing framework?

If possible please post some code with examples to clarify the ideas.

Any help on this topic is very welcome! Thanks.

0 views   0 shares
profilepic.png
manpreet 2 years ago

Let's start with the obvious:

How does testing work ? In test-driven development you first think about the functionality you want to implement and then write a test for it. In the example you gave of a sum function it is quite obvious what it should do. You then write a test that makes sure that the summation worked.

Unit tests should be as lightweight as possible so you can run them each time you hit the build button. When you do this now in this example your test will fail, because you have not yet implemented a sum function.

Now you write the actual function and continue debugging and implementing until the test passes. Then you are sure you have implemented the feature you wanted.

Now how should you design your test ? You cannot test all, that is impossible. As an example lets say you take user input you have to validate. Then it would be a natural thing to write at least two test cases for that validation code: one that makes sure that valid input is parsed as such. The second test case gets invalid input and you make sure that it fails, raises an exception or whatever behavior you desired. So in this case it is good to have a positive test which is expected to pass and a negative test which checks if invalid input is not validated.

When should one test? As I mentioned before the test should be lightweight enough so that they can be run on each build. And yes, run all of them. This makes sure that you do not miss a dependency in your code that breaks things far away from the point you edited.

Can anything be tested ? Well, usually methods that rely on external ressources are hard to test. What I mean by that are databases, network connections or specific hardware and drivers. It can be done but then you have to set up a larger test setup.

Bugfixing and tests A typical scenario where test get really useful is if you are squeezing bugs. Not literally of course. If you have a bug you have to fix, first try to write a test for it. And then fix your code until your test passes. From this point on this test "watches over your code" that this bug will never come back again.

What do you gain by testing ? In my opinion there are many things

  1. More modular, easier to maintain code because it has to be testable
  2. Confidence. Having a code base that is largely tested gives you the confidence that it works as expected and stays like this.
  3. You find bugs early. This means you can fix them more easily.

It takes some effort to get used to using tests but I think it is worth it. Especially if you are writing libraries of some kind.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community