Search code examples
unit-testinglanguage-agnostictestingmain-method

Using the main method of classes for debugging?


It is good practice to use the main method to test a java/.net class?

I've seen it reccommended in some text books, but to me it seems like using a unit testing framework would make more sense...

The main method gives you one point of entry to the class and you can test one aspect of the classes functionality. You could I guess test many but it doesn't seem to make sense as much as using Junit or Nunit.


Solution

  • One obvious advantage seems to be that you can whitebox test the class. That is, you can test the internals of it (private methods for example). You can't do that with unit-tests, nor would you wan't that, they are primarily there to test the interface and the behavior from the users perspective.