My JUnit tests work on startup in Eclipse, but sometimes they accidentally fail through Ant

The core of my question is that I am concerned that the Ant build file is missing something that will complete the test and clear it. Details below.

I have a test suite that always passes when I run it through Eclipse, but sometimes skips or fails when I run it using my Ant construct. Tests use openCL through JOCL, so I have limited memory on the GPU and need to be managed properly. I get this in my release when I run my Ant construct,

[junit] Caused an ERROR [junit] CL_MEM_OBJECT_ALLOCATION_FAILURE [junit] org.jocl.CLException: CL_MEM_OBJECT_ALLOCATION_FAILURE 

The problem cannot be in the test itself. I think my most hungry memory test is called at the end of the packet. When this last test is called, somehow the GPU remains in a bad state from my previous tests. This does not happen when I run tests through Eclipse. It never lost in my Ant construct when I do the hungry memory test for the first test in the kit. Is this a familiar case? Why does running tests through Eclipse always work? Is there anything I can try?

Here is the purpose of testing in my Ant build:

 <target name="test" if="testing.enabled"> <mkdir dir="${test.bin.dir}" /> <javac srcdir="test" destdir="${test.bin.dir}" debug="true" classpathref="testclasspath" source="1.6"/> <junit haltonerror="true" haltonfailure="true"> <classpath refid="testclasspath"/> <formatter type="plain" usefile="false" /> <batchtest> <fileset dir="test"> <include name="*Test.java"/> </fileset> </batchtest> </junit> </target> 
+7
source share
4 answers

If you are really sure that there is no missing cleanup in the code, you can create a JUnit test suite and run it from both eclipse and ant. By creating a test suite, you make yourself independent of the sequence of tests that are overshadowed (order in the project?) And ant (order in the file system?) They use and determine the order themselves in both cases.

If you are really not sure that your code is no problem, you can create a test case that starts by calling Collections.shuffle() in the list of test classes to enter an unknown order of the test in both eclipses; look, it will never work.

+5
source

The problem may be that you are not freeing up memory in your test cases. As far as I know, JUnit initializes all test classes when it is running, and then runs them. If you have fields that reference objects in your test classes, all fields will remain assigned through the entire test call, unless you assign null them in the tearDown() method. For example:

 class Test extends TestCase { private Data data; public void setUp() { data = new Data(); } public void tearDown() { data = null; // required to allow garbage collection of the Data object } } 

Perhaps Eclipse unreferences instances of Test after they are executed, so that the fields can be garbage collected. But using the standard JUnit TestRunner, you will get a lot of objects that are no longer used, but they are still referenced and eaten up all your memory.

+3
source

If the tests pass in Eclipse and do not work elsewhere, then you suffer from one of many types of developer syndrome: "... but it works when I run it here ...!"

You managed to configure Eclipse so that you can work with your code, the functionality in it, but your code is still not deployed, which means that it is not done.

Quit Eclipse for a while (stop blaming it) and go to the command line (or use a different IDE) until everything works. Try the code on another computer, even!

Then go back to Eclipse and repeat the above cycle until you are sure that all dependencies on Eclipse or your hard drive / installation have been removed. In the end, your code should be able to run who-known-which on the server.

Have you tried having a clean Eclipse installation (on another computer) to take a snapshot only for the source code? This would be a good configuration management test, which I am pretty sure that your code will not pass in its current form.

Seriously try to get Eclipse to do its magic on a clean (virtual) machine. It will not work the first time you start, but you will find out what you did to make it work for your setup.

+2
source

Let me tell you what for you:

Ant is looking for an environment variable called ANT_OPTS that is used to set Java parameters. > Just set the environment variable and release. So I added the following to increase the heap size:

export ANT_OPTS = -Xmx256m

When working with the Eclipse JVM (and therefore Ant), it most likely already has more memory than the default.

0
source

All Articles