What is the advantage of using JUnit to test methods of a class?

6

I've created an application that basically is a class that tests whether the methods of another class are returning the expected values. My teacher asked me to rephrase this class as a JUnit test case. I did as he asked, but in the end I get the same result as when I use only a normal class. What advantages can I get from JUnit in this case?

    
asked by anonymous 05.04.2016 / 15:12

2 answers

5

JUnit is a framework to produce tests. He knows better than programmers how to do it right. Everything is ready for your use. Of course the programmer needs to know how to use it.

The advantage of testing is whether the method is meeting the requirements specified in the test itself. You can modify your normal methods and run JUnit to see if your modifications did not compromise the result of the modified method. You'll see more advantages when dealing with large code bases. But you're learning to do it right from the start, even in exercise codes.

Specifically JUnit has a structured way to manipulate the tests and deal with their results. If you write them the way JUnit requires, the tool will be able to make the best use of this information and determine if everything is okay, all without human intervention. This way can help integrate with other JUnit-compatible tools.

Proper use of your resources can better document problems encountered if a test fails. This is useful for many tools and for the whole team. Whenever you have a standard shape you will have the most organized work.

It can, as a whole, help create tests and data to confront behavior, as well as facilitate certain types of tests that would require a specific infrastructure to run. Obviously it's just a process automation tool. It does not make your code look better, nor does it make your tests correct. If the tests are poorly written, little or nothing helps. It can give productivity and reduce the boring part of writing tests in addition to avoiding some common mistakes and forgetting.

In addition, it encourages you to create pre-code tests, called TDD .

    
05.04.2016 / 15:43
0

I understand that the big advantage is mostly one , the same one that makes me use JAVA: Standardization.

If you use a mini framework you've done for testing instead of using one that is already tested , documented , and largely developer and testing programmers will be needed when you need 300 your application? They will have to learn to use this testing framework, they will not know if they will continue to do so in the future, etc. Things that when you use market frameworks is much easier, cheaper and standardized to work with.

So the moral of the story is: It's better to go coaching the way the market works to be a good professional in the future

    
06.09.2016 / 20:12