The funniest piece of unit test code I have seen in long time
Added: August 25, 2009
While I was wading through some tests recently I have found following piece of code. I thought you might enjoy it too.
@BeforeClass public static void setUpBeforeClass() throws Exception { System.out.println("BeforeClass"); main(null); } public void testDummy() { // do nothing } public static void main(String [] args) throws Exception { System.out.println("main"); // a lot of code is here }The point is that given test class is meant for setting up an environment and it does not contain any real test methods. It is just an inconvenient way to use convenience of JUnit for execution of some code. Please, do not do these things!
I had some problems to search for all necessary details so I am going to publish my little script here as it might be useful for somebody.
In my work I need to keep several console windows open (on Windows) in order to produce jar artefacts from several dependent projects without a need to use our build server. Sometimes it got a bit out of control when I needed 6 or 8 of them opened at the same time and was not easy to find partcular one quickly. So I have decided to create a script that changes console title to working directory (only last directory).ti.bat
:
@echo off setlocal set name=%cd% set name=%name:*\=% set name=%name:*\=% set name=%name:*\=% set name=%name:*\=% set name=%name:*\=% set name=%name:*\=% set name=%name:*\=% set name=%name:*\=% set name=%name:*\=% set name=%name:*\=% title=%name% endlocalExplanation of non-obvious things follows:
set name=%cd%
gets name of working directory.- following collection of lines is my workaround for a loop that did not work for me well. If you can help me to get rid of this duplication (and limit to 10 subdirectories) I will be very glad.
set name=%name:*\=%
removes text from variable up to the first backslash or it does nothing if there is no backlash.-
setlocal, endlocal
keep changes in variables private for script execution, changes are forgotten when it ends.
ti [ENTER]
and the title is nicely renamed from original not very useful C:\WINDOWS\system32\cmd.exe
to something like dao_testing
.