In Python it is common to have "doctests" - simple tests inside the documentation of classes and methods. Their main advantage is that they can easily be executed while editing the code - when I change some code, I can run all tests with a single click, I do not have to open another file.
In Java AFAIK there is no "doctest", but a similar functionality can be implemented by just adding to the class a "main" method with some basic documented tests. Then, again a programmer changing the code can immediately run the tests to see if anything is broken.
I haven't seen it done frequently. One possible reason is that it makes the class file slightly larger, but this seems negligible. Are there any other disadvantages to this practice?