Category: Java
Ant, Junit and Assert
November 7th, 2010ant and junit
WWW has a lot tutors on using junit with Ant, such as Tutorial: Hello World with Ant. But if you following it, you'd find ant complains about something. Here are some points I find:
- You must install ant full if you want using embed junit. You need to run following command in the directory you just unpack ant binary
ant -f fetch.xml -Ddest=system. It'll install all the dependency java libraries for ant tasks.Please see http://ant.apache.org/manual/install.html - Ant will automatic to include junit-x.x.x.jar in classref, but you must write a target to explicitly compile test sources to test classes.
ant and assert
For enabling assert in runtime, java must be invoke with option -ea. And for ant, build.xml must add <assertions> in <java> and <junit>. For example:
<assertions>
<enable />
</assertions>
ant and proxy
For java version 1.5+, please using following command to complet ant install process:
ant -autoproxy -f fetch.xml -Ddest=system.
More info can be getten from here
EasyMock for junit\
Mock object is needed for unit test. For java, there are tons mock lib. After a rough study, I choose EasyMock due to it is similar to the mock lib I used in Ruby. There is no good official document for EasyMock, but I found a great blog which can be seen as document of EasyMock: http://jeantessier.com/SoftwareEngineering/Mocking.html
Java Html Parser
October 23rd, 2010In Java World, HTML Parsers play a role that change dirty, untidy html pages in real word into a well-formatted HTML files.
Pure-Java Solution
Here is a summary page: Open Source HTML Parsers in Java
Using Firefox-DLL
Besides all these, there is a method to using firefox-dll to parse html. This method can get best result.
But this method is very hard to deploy and easy to broken.
Benchmark
Here is a benchmark result, which shows that CyberNeko is winner.
Javascript and CSS2 support
However, if you want to support javascript and css2, Cobra could be a good answer. Please check following blog Using the Lobo Cobra Toolkit to Retrieve the HTML of Rendered Pages
Run jar file in command
January 13th, 2010java -jar file_name_of_jar