Learning Java Programming with Automated Tests

    It all started with a simple one my friend wanted to write programs in Java. Naturally, just by learning the syntax of the language, you will not have any programming experience, and therefore you just need to write at least something. So I was pondering the question of what is best suited for this. I came to the conclusion that the best thing at the beginning of the way, in my opinion, is to create a simple class that would describe an abstract "entity", but at the same time be easy to understand. As a result, it was decided to issue a training task on writing a self-made class of complex number.
    Of course, one could simply write on a leaflet all the requirements for this class, describe the interface of all its methods and the like, but then it would have to be checked, and it is very likely that it will be checked several times, since a friend is just learning.
    But here I was attracted to experiments, and since I had not been interested in TDD for a long time, the experiments went to the same steppe.


    And so, I thought, why not take it and place the task in the form of a set of tests that would, firstly, speed up the development process, since in case of an error, the reason is immediately displayed on the screen, and all that is needed is to show imagination and edit the code so that the cause of the error has been fixed, and secondly, it will allow you to step-by-step complicate the program, while controlling every step and result.
    Plus, in this way, you can instill good-style rules, using getValue / setValue methods like using public fields instead of simply using tests to control the existence and correct operation of these methods.

    And now it's time to code. The first thing I decided was to run all the tests inside the main function through regular method calls. What is the reason for this? Everything is simple - the main task is the step-by-step creation of a class, with a gradual increase in its complexity, which is very easy to arrange by specifying a sequence of calls to testing methods and exiting the program if one of them fails. Also, in order to find out what the test results are, simply press F6 (I did this in the netbins), find out what exactly works wrong from the output window, and continue editing the code.

    I decided to build this simulator in the form of a "sequence of actions", as a result of which a complex number class is independently created, and its methods are implemented. This is all implemented in the form of automatic tests that check for the presence of a class, then the availability of the necessary methods, then they begin to check the results of these methods, and so on.

    The result of all this was an application that “coaches” a beginner in creating small classes. Immediately make a reservation that it means knowledge of the syntax of the language at least at the level of writing valid constructions.
    Of course, one cannot grow a programmer with such an application, however, for beginners, this method of training can be a good indicator of where to go the way further.

    For everyone who wants to test on themselves, what happened in the end, I suggestDownload archive with the project (for netbins). The rules of use are simple:
    -Open the project
    -Open the file doxygen / html / index.html (it contains explanations of the requirements and some useful information, as well as descriptions of everything under the hood)
    -Follow the application and follow the instructions in the output until all tests will fail.
    All this should take about an hour.
    I will be glad to constructive criticism.

    The last question is - does such training make sense and will there be an effect on it?

    Also popular now: