I've been learning C# lately to see the other side of the coin (I have a decent amount of Java knowledge already) so I've been reading up on C#, and I came across an article called C# for Java Developers, and in reading the article, I saw something that I had never heard before.It is typically recommended that one creates a main method for each class in an application to test the functionality of that class besides whatever main method actually drives the application.I've never done commercial development, so maybe this is an industry practice that I just haven't heard of, but surely somewhere in the various books I've read it would have come up. Is this really a thing? Is it common to do this?
C# / Java: Should every class have a main method?
java;c#;unit testing;testing;class design
Most developers use a testing framework, such as JUnit, for their tests.  These (so far as I now, there may be exceptions) do not require writing a main() for every class.If you are not using a framework, it might make sense to do testing via a main().  However, don't do that.  Use a testing framework.  It makes your life way easier, allows for continuous integration, test/code coverage and metrics, lots and lots of good stuff.Note:  For a GUI class, I will sometimes write a main() to bring up the custom MySuperWidget in a JFrame and show it off for quick visual testing.  This is an exception, not the rule.