Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Robin Clark

Ranch Hand
+ Follow
since Dec 17, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Robin Clark

I am tasked with trying to convince my co-workers that they should unit test BEFORE they integration test. Our corporate culture is one where no pure unit test cases have ever been written. All repeatable testcases that are written use many objects (not just the class under test). The problem is that these testcases are very sparse, don't usually test the throughly and they break after one release because they are dependent on other objects and database contents.

The pushback that I am getting from people is as follows:

1) We don't have time to write unit test cases for methods that are not being changed (and of course there are no previously written unit test cases because we didn't have time in the last project)
2) It is quicker to write integrated tests...it saves a step
3) Writing unit test cases (with mock objects) doesn't really test the code

I am a total convert and believe that time can be saved by writing repeatable unit test cases before you even think about executing integration tests. But I am a poor salesperson and am having trouble convincing others that they will save time and have a better life by embracing unit testing.

Can you please help me by pointing me towards some really compelling evidence to convince others?

Thank you.
4)
13 years ago
I'm working on a web app that does alot of translating from one record format to another for rather large objects. I am testing a class called MyWidgetValidator that calls an external api, passing it an input parameter and receiving back an object of type OutsideWidget. MyWidget does some validation and then copies all of the fields from the OutsideWidget record format to the MyWidget record format. There are ~30 fields on the OutsideWidget and the MyWidget.

I'm assuming that my junit testdriver should validate that all of the fields have been copied correctly from the OutsideWidget to the MyWidget. But coding all this logic is tedious and boring. One time wouldn't be bad, but I need to do this for many classes.

Is there a way in Eclipse to automatically generate this code?

The end result of the code in my dummy/Mock Object for the external api looks like this:



The code in the class I am testing looks something like this:



and the code that I will write in my testdriver to validate it will look something like this:



It is all very simple stuff and requires too much typing.

Thank you!
13 years ago
Should you only create a mock object to replace code that calls external apis, databases, etc?

What if I am testing a class A, that uses another class B, with very complex functionality. I can see that class B does not call any external apis or make any database calls. I can see that class B uses three other classes...C, D, and E and I don't know if C, D and E call external apis or not.

Should I
a) create a mock object to replace B
b) investigate C, D and E to see what they do

The problem with "b" is that C, D, and E can also use many classes each of which would need to be investigated and at least partially understood.

It is clear that this code is tightly coupled and needs to be re-written in the long term. But I am trying to write some unit test cases and my short term constraint is that I can not modify the classes that are being tested.

Thank you.
13 years ago
I am the poor sap that has come along six months after the project was finished and told to write junit testcases for existing code. The code stinks to high heaven. It is a huge application written by a large company and it is possible to get approval to promote unit test code that will not be executed in production, but it takes an act of god to make changes to production code. This is why I can't modify the actual class I am testing, at least until the next release goes in which will be some time next year. So I am going to try and figure out how to change the class path for just my junit test execution. I can't change production build scripts either.
I am writing a junit testcase that tests a class, A, that uses a very complex class, B. I would like to create a mock object that will replace B and will be used when I run my junit test case instead of using the very complex B class. The problem is that I can not change the code in the class that I am testing. So I have to name my mock object the same as the complex class. When I create the mock object, B, I am naming it the same, but I am putting it into a different directory. In Eclipse I am getting the error, "The type B is already defined".

How can I get around this problem?

Thank you.
I am using Eclipse 3.1.2 and MyEclipse 4.1.1. Although the .class files in WEB-INF/classes get automatically copied to my deployment directory, the MessageResources.properties does not get copied to the deployment directory. If I manually copy the file, the application works fine.

Can someone explain the mechanism by which the IDE knows which files to copy to the deployment directory? How can I configure Eclipse to automatically copy the MessageResources.properties file to the deployment directory?

Thank you.
I am getting the above error in my index.jsp. My web.xml looks like this:



My index.jsp has the following:


My web app directory structure is as follows:

WebRoot
->WEB-INF
->->struts-html.tld
->->struts-logic.tld
->->tags
->->->struts-html.tld
->->->struts-logic.tld

Note that I have struts-html.tld and struts-logic.tld under BOTH WEB-INF and WEB-INF/tags but they are still not being found.

When I start my application server and execute the application, I receive the following error:



If I use the following code in my index.jsp the application works fine:



Can someone explain to me why I am having troubles accessing the tld files locally?

Thank you.
13 years ago
I'm using Eclipse and MyEclipse. I can't figure out how to "import" an existing war file into my Eclipse Project. When I do the File->Import->Archive File, the list of file types does not include .war. Is there a way to incorporate an existing war file into a new Eclipse project? I would appreciate any directions or links to documentation that can help me with this. I can't find this topic in the Eclipse and MyEclipse documentation.

Thank you.
Looks like you gave me the answer while I was writing my previous post! Thank you. I am experimenting with the Runtime exec method as we speak.
14 years ago
Is there a way to invoke the gunzip command in a Java class? What I need to do is to read a file that has a ".Z" suffix in memory, looking for a specific string. When I find the string in the compressed file, I want to write out the 1000 lines that occurred prior to seeing the string in the file and write out the 1000 lines that follow the string. I want to write to a plain text file.

I know that I can do this in perl by invoking the gunzip command to create a temporary uncompressed file. Then I can read thru it looking for the string. And I can delete the temp file when I am finished.

But I'd rather do this in Java so that I can practice my Java skills.
14 years ago
I decompressed the file by using this command:

gunzip csm.log.2006072106.Z

Then I recompressed it by using this command:

gzip csm.log.2006072106

This created a file called csm.log.2006072106.gz which I was able to read using the code in the previous post. However, I need to find a way to process the file when it is named csm.log.2006072106.Z programatically.

Any ideas?
14 years ago
I have written a program to uncompress a ".Z" file on Solaris. When I run it I get the following error:

java.io.IOException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:129)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:57)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67)
at Log.main(Log.java:12)

Here is the program:


What java class do I need to use in order to read a .Z file in a java program?
14 years ago
Here are the reasons that I would use a singleton. I would use a singleton if I wanted to share resources. Everyone could instantiate the object and certain activities would only have to occur once like getting a database connection.

But if I didn't want to share resources, I would absolutely think that the singleton pattern would be pointless.

Am I confused about why to use the singleton pattern? What are the benefits to the singleton pattern if not to share resources?
I've got two strikes against me. First I can't get my head around threads. Second, although I understand what the singleton pattern is, I don't understand why you would want to use it to protect memory. Everytime I ask someone why the singleton pattern is used they tell me that it is to protect memory and they wave their hands around in the air. Is this a big hoax perpetuated by someone who gets a commission everytime the singleton pattern is used? Or is there a solid explanation as to how the singleton pattern protects memory?

In my mind, it seems like it should be the other way around. That the singleton pattern causes MORE problems because the same instance variables are being by multiple threads.

Here is the way that I look at the situation--threads are bratty little children and objects are shiny red fire trucks. Instance variables are the little plastic men that ride on the fire trucks. A class variable is the single firehose that exists to hook up to all the firetrucks. In a singleton class fire truck all the bratty children are playing with the same toy. There is one plastic man and one firehose. Wouldn't it be better if this was not a singleton class and every child had their own fire truck with its own little plastic man so that they didn't interfere with each other?

Please help me to clarify my understanding.
14 years ago
For years I have not understood why the singleton design pattern is used. I understand what the singleton pattern is, I just don't understand "why". Can someone direct me towards some pictures that depict what happens to static data members and non-static data members in a multi-threaded process that would cause problems for a class that was not a singleton? And then a picture of what happens to fix the problem in a singleton class? I've read many descriptions over the years but still can not visualize what occurs in memory for:

threads
singleton versus non-singleton
static data members
non static data members

Please keep the explanation as simple as possible because I must be extremely dim-witted about this concept!

Thank you!