0

I am a QA personnel of a bank in my country. We have a lot of applications with legacy code that are really old and haven't been tested with white box process. Here, we also regularly got projects and changes to those code as requested by the business unit.

My team and I are planning to have a unit test for them by using JUnit. We know that it is hard to add test scripts for them, so what we want to do is to add the unit test for the new project/changes first.

But then, after a brief discussion with the developer team, they are unsure of the idea. So, I need your opinion and advice for this project.

Thank you very much

Reinaldo
  • 44
  • 5
  • Unit tests, as the name itself says, are tests for testing most basic units of work. Every unit should be covered by tests. But it's nice to have thing. In business you need to think of need to have things, because time is money. So, cover all the new work (change requests) and the rest you can cover later, if there is no other work to do. – JiKra Sep 24 '15 at 09:33
  • Yes, that is what we thought - add unit test for the new changes. But the concern of the developer is that if a method that we tested fails and the method refers to another class that they don't know. What do you think of it? – Reinaldo Sep 24 '15 at 09:39
  • Oh yes, one more thing. The developer also said that it is not possible to add unit test to a legacy code. We should create unit test from the beginning, not in the middle. Is it correct? Because I still think it is doable. – Reinaldo Sep 24 '15 at 09:42
  • Unit tests should indeed be written together with the project itself. But if you want to change code without breaking it, you'll need to write tests now. It is doable, but boring and time-consuming. – Manu Sep 24 '15 at 09:45
  • I'm not planning to add the unit test to cover the whole code, cause we all know it is freaking hard and time consuming. But how if I do just the newly developed changes? Is it recommended? – Reinaldo Sep 24 '15 at 09:50
  • It depends on code. If it's full of hidden dependancy mess, it should be really hard or sometimes nearly impossible to do that. That's why I said that you should cover only the necessary minimum of code, including dependancies. Still you need to think of unit tests on legacy code as of the nice to have thing. If it works, let it work. Otherwise it will cost you a money. – JiKra Sep 24 '15 at 09:51
  • Your newly developed changes might break other parts of the code. If you don't care about that, you don't need to write tests. – Manu Sep 24 '15 at 10:01
  • @JiKra The code is indeed impossible to read. Haha. Well I'm trying to do it on a pilot project, see how it will work. Thanks for your opinion btw. – Reinaldo Sep 24 '15 at 10:02
  • My 2 cents. Listen to the developer. If he/she thinks this isn't doable, it probably isn't. In my experience (and I'm an old bitch!), systems are never written in a testable way if tests have not been a priority from the beginning. – Glennie Helles Sindholt Sep 24 '15 at 10:14
  • @Glennie Well, I think that is not the case. The code is about 10 years or more and at that time testing is never been the thought. Do you believe that they code with notepad? But again, the developer know more than me.. or they just don't want extra works – Reinaldo Sep 24 '15 at 10:34
  • @Reinaldo What's wrong with notepad? :-D Just kidding. But seriously, I do not think this has anything to do with developers not wanting the extra work. To write good tests, code needs to be well structured and follow some general design principles, such as separation of concerns, interface segregation and dependency inversion. A 10 year old system with no existing tests has roughly zero percent change of obeying these principles. – Glennie Helles Sindholt Sep 24 '15 at 10:49
  • @Glennie I was just joking too about them not wanting extra works. Haha. By the way, what you've said is what I've been thinking as well. There will be errors everywhere. But my question is that can we just focusing the test to the functions of the new changes? We ignore if it's meddling with the older code.. – Reinaldo Sep 24 '15 at 10:56

1 Answers1

0

A unit test helps ensure that a feature works correctly but it also helps detect (some) regressions as future changes break the existing behavior. So if you are creating unit tests only for your new changes you will miss the regression detection capabilities.

Writing unit tests for existing code, even though its not the most exciting activity for a developer, has the advantage of documenting the code and it helps the development team to get a better understanding of the legacy code.

All in all you and team should consider creating unit tests for all the critical scenarios as having equal priority with adding tests for new changes.

  • The code and application will got functionally tested afterwards, so I think it doesn't matter if we miss the regression capabilities. Without unit test, we also miss the regression testing, right? But I agree with your point about creating the documentation for the long term development. Unit test will help testing the code faster in the long run as well. About the critical scenarios, we will think it afterwards cause I need to ask the developer further more. So what do you think of adding unit test for the new changes? I'll mark your answer as right if you give further opinion. Thx – Reinaldo Sep 24 '15 at 10:30
  • That assumes that for every change you correctly determine all the areas that were affected and perform all the manual tests. This is risky especially in the late stages of development. Unit tests do not replace functional testing and do not guarantee your code is defect free but since they can be run automatically at build time they provide a good, cheap first alarm system. Regressions detected by unit tests are quick to found (after they are introduced) and are easier to debug since you need to inspect only the changes between the current build and the last successful one. – Dragos.Cojocari Sep 24 '15 at 11:37
  • Okay, I get your point. Well, I'll still gonna try to implement it and see the result first. So by the way, do you recommend us to use unit test or not, cause I see some benefit we could get.. – Reinaldo Sep 24 '15 at 13:05
  • I use unit tests in all my projects and they help tremendously. So yes, I recommend using unit tests **in addition** to all the other QA tools and techniques. – Dragos.Cojocari Sep 24 '15 at 13:48