I’ve created a JavaWeb Project in Netbeans7.2 following the book Beginning JavaEE6 Platform with GlassFish3 2nd edition. The book uses Maven and commandline to compile and package while I’m using Netbeans.
The problem is that it wrote a main function to test a few functions(create/update the Book entity and ouput some infomation by System.out.println(info)). But I can’t get the project run through the main function in Netbeans, it always opens the web browser and shows me 404….
What should I do if I don’t want to create web pages but just run the project through main function like javase in Netbeans? Thank you!
If you want to test some features you have added, write your tests inside JUnit tests.
Test only the code your have written with appropriate use of mock objects, which provide a good way to emulate your code dependencies i.e. others layers of your webapp like DAO, DTO, etc.
Plus it could be very good to use mock objects because you can emulate behavioral stuff like testing if your code could handle some exceptions gracefully. It becomes very handy your code depends on some exceptions tree.
Some mock objects libraries:
Forget the idea to include your tests inside main methods.
It is not a good practise in web development.
Maven provides good plugins to test within a container.
Look at the cargo plugin, or the war plugin.
But of course, you will need to write some JSPs.