Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account
List archives

Trying to get Ant + JUnit working peaceably

fileset and java tasks?
(12 lines)
Junit Task dies with NullPointerException
(23 lines)
Jun 5, 2010
Steven Harms
Steven Harms
Hello,

I'm attempting to learn Java at present and needed to add some
automation around my build and test cycle.  Coming from Ruby, I've got
a real test-first design discipline.

When I attempted to make a <junit> task call, I started getting this
error (I can hear eyes rolling...).


BUILD FAILED
/Users/stharms/java_card/build.xml:38: Problem: failed to create task
or type junit
Cause: the class
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.
        This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
        -/usr/local/apache-ant-1.8.0/lib
        -/Users/stharms/.ant/lib
        -a directory added on the command line with the -lib argument

OK, I'm open to trying to step through the directions.

Most searches and archives suggested that it was paramount to make
sure that the junit library was in $ANTDIR/lib.

In this directory I have both:

junit-3.8.2.jar : retrieved with ant -f fetch.xml -Ddest=system
junit-4.9-SNAPSHOT-20100512-0041.jar : built from github

I then thought, OK let's go with the instructions strictly, what's in
the lib/optional subdir.  Nothing!  OK, so I used the fetch.xml task
to pull the jars into optional.

Re-try, same error.

OK, IRC.  A kind soul there pointed out that on his debian system this
class file was part of optionals.jar that "just worked" as part of
using apt-get ant-optionals.  Hm, regrettably that answer isn't
portable to my platform.

So, I'm stuck.  Can anyone help me get around this low point.  I'm
excited to start programming Java, but I've wound up programming Ant
most of the day -- not a bad thing, just not the shiny app I had
dreamt of :)

Thanks in advance, mysterious guru with the answer,

Steven


Reply
Tags: attemptingcalltask
Messages in this thread
Trying to get Ant + JUnit working peaceably
Similar Threads
Created: (DERBY-4747) ttestSetPortPriority junit test failing in tinderbox runs with junit.framework
ttestSetPortPriority junit test failing in tinderbox runs with
junit.framework.AssertionFailedError: Port 1537 exceeeds expected maximum.

iPOJO OSGi Junit Runner error, no junit command
I'm trying to get the iPOJO OSGi Junit Runner to work.  When I start the
bundle I get the following messages to the log:

LS: Scheduling task ManagedServiceFactory Update:
factoryPid=org.apache.felix.ipojo.junit4osgi.impl.JunitExtender
LS: Running task ManagedServiceFactory Update:
factoryPid=org.apache.felix.ipojo.junit4osgi.impl.JunitExtender
LS: [ERROR] org.apache.felix.ipojo.junit4osgi.impl.JunitExtender : Cannot
create the proxy object
LS: [ERROR] org.apache.felix.ipojo.junit4osgi.impl.JunitExtender : The
onArrival method onBundleArrival has thrown an exception
LS: ServiceEvent REGISTERED
LS: ServiceEvent MODIFIED
LS: [ERROR] org.apache.felix.ipojo.junit4osgi.impl.JunitExtender :
[org.apache.felix.ipojo.junit4osgi.impl.JunitExtender-0] The callback
method
starting has thrown an exception : null
LS: ServiceEvent UNREGISTERING
LS: [ERROR] org.apache.felix.ipojo.junit4osgi.impl.JunitExtender : The
onDeparture method onBundleDeparture has thrown an exception

I assume the message means the JunitExtender.onBundleArrival and
JunitExtender.onBundleDeparture have thrown an exception and this is why
things aren't working, but don't know why (what's the exception?).

The odd thing is I can get this to work on my Windows environment, but
this
problem is happening on my target environment (Linux, ARM)


PIG + Junit
I'd like to include running various PIG scripts in my continuous build 
system. Of course, I'll only use small datasets for this, and in the 
beginning, I'll only target a local machine instance. However, this 
brings up several questions:


Q: Whats the best way to run PIG from java? Here's what I'm doing, 
following a pattern I found in some of the pig tests:

1. Create Pig resources in a base class (shamelessly copied from 
PigExecTestCase):

     protected MiniCluster cluster;
     protected PigServer pigServer;

     @Before
     public void setUp() throws Exception {

         String execTypeString = System.getProperty("test.exectype");
         if(execTypeString!=null && execTypeString.length()>0){
             execType = PigServer.parseExecType(execTypeString);
         }
         if(execType == MAPREDUCE) {
             cluster = MiniCluster.buildCluster();
             pigServer = new PigServer(MAPREDUCE,
cluster.getProperties());
         } else {
             pigServer = new PigServer(LOCAL);
         }
     }

2. Test classes sub class this to get access to the MiniCluster and 
PigServer (copied from TestPigSplit):

     @Test
     public void notestLongEvalSpec() throws Exception{
         inputFileName = "notestLongEvalSpec-input.txt";
         createInput(new String[] {"0\ta"});

         pigServer.registerQuery("a = load '" + inputFileName + "';");
         for (int i=0; i< 500; i++){
             pigServer.registerQuery("a = filter a by $0 == '1';");
         }
         Iterator<Tuple> iter = pigServer.openIterator("a");
         while (iter.hasNext()){
             throw new Exception();
         }
     }

3. ERROR

This pattern works for simple PIG directives, but I want to load up 
entire pig scripts, which have REGISTER and DEFINE directives, then the 
pigServer.registerQuery() fails with:

org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1000: Error 
during parsing. Unrecognized alias REGISTER
     at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1170)
     at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1114)
     at org.apache.pig.PigServer.registerQuery(PigServer.java:425)
     at org.apache.pig.PigServer.registerQuery(PigServer.java:441)
     at 
com.audiencescience.apollo.reporting.NetworkRevenueReportTest.shouldParseNetworkRevenueReportScript(NetworkRevenueReportTest.java:74)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Any suggestions?

-Todd


Timeout in junit and sysout
Hello,

 

some of our Junit tests run sometimes into the timeout I have set.

Sadly we do not see any sysouts in my logs.

 

Do I have to use system.out.flush or how can I make this sysouts visible?

 

Juergen

 



icon Systemhaus GmbH                Tel. +49 711 806098-275

Sophienstraße 40                    juergen.### @icongmbh.de

D-70178 Stuttgart                   Fax. +49 711 806098-299

 

Geschäftsführer: Uwe Seltmann

HRB Stuttgart 17655

USt-IdNr.: DE 811944121 

 

 



Is Junit.jar is mandatory for Apache DS 1.5.7?
Hi,

This is a follow up question of  email 'Upgrading to Apache 1.5.7'.  we
also
have approval problem for junit-4.7.jar.  Is this mandatory for Apacheds
1.5.7?  I tried removing it but it is used in DSAnnotationProcessor class?
is this is a required class or optional?  What exactly this class do? How
to
see this is working in Apache DS? How can I remove it and make sure that
nothing breaks? Please help.



Junit Task dies with NullPointerException
Having surmounted the Ant-as-technology issue, I'm now encountering an
error in my ant execution of junit.  When I run my ant script, I get:

java.lang.NullPointerException at
org.apache.tools.ant.taskdefs.optional.junit.FailureRecorder$TestInfos.<init>(FailureRecorder.java:349)

(The full stack is here: http://gist.github.com/427394

My source files are available at:

http://github.com/sgharms/javacard/tree/anttune (heck, you could even
git clone it and try it out yourself ;) )

If I turn off the 	<formatter type="failure" usefile="false"/>
specification, the output is more terse, but the operation definitely
fails as well.  I don't see that it's a particular line of my class
that's setting off the stack-bomb, so I'm not so sure on how to debug
this.  Any advice would be appreciated.

Steven


junit tests running slower in 1.8 than in 1.7
My team has a unit test suite that ran in about a minute and a half
with ant 1.6.5 (and 1.7.1), but now takes over 4 minutes with ant
1.8.1 (or 1.8.0).  Has anyone else had this problem?  The closest I've
found via google is here, but it doesn't shed much light on the
subject:

http://netbeans.org/bugzilla/show_bug.cgi?id=182263

We're running junit with fork=yes and forkmode=once.  With forking
turned off, the tests run much faster, about the same as in 1.7.  (But
we want the forking for other reasons.)

We're running under Windows, with jdk 1.6 and junit 4.5.

Have you seen this problem and worked around it?  Is it a known issue,
or a problem with our configuration?

For the curious, I've created a simplified project here:
http://web.mit.edu/lgdean/Public/test-project.zip .  I've also
attached test results below, showing the difference (with much smaller
numbers), and a snippet of the build.xml file.  Any advice would be
appreciated.

Thanks,

Laura



C:\ant-trouble\my-project>ant -version
Apache Ant version 1.7.1 compiled on June 27 2008
C:\ant-trouble\my-project>ant test

test:
    [junit] Testsuite: SomeJUnitTest
    [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.042
sec
    [junit]
    [junit] Testsuite: SomeOtherJUnitTest
    [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.032
sec
    [junit]
    [junit] Testsuite: YetAnotherJUnitTest
    [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.034
sec
    [junit]


C:\ant-trouble\my-project>ant -version
Apache Ant version 1.8.1 compiled on April 30 2010
C:\ant-trouble\my-project>ant test

test:
    [junit] Testsuite: SomeJUnitTest
    [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.044
sec
    [junit]
    [junit] Testsuite: SomeOtherJUnitTest
    [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.122
sec
    [junit]
    [junit] Testsuite: YetAnotherJUnitTest
    [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.108
sec
    [junit]


    <target name="test">
        <junit fork="yes" forkmode="once">
            <formatter type="brief" usefile="false"/>
            <classpath> [...] </classpath>
            <batchtest>
                <fileset dir=".">
                    <include name="**/*Test.java"/>
                </fileset>
            </batchtest>
        </junit>
    </target>


Setting maxmemory for JUnit tests
I was running into an out-of-memory error while running the  
org.apache.avro.mapred.TestWordCountSpecific and TestWordCountGeneric  
tests:

     [junit] java.lang.OutOfMemoryError: Java heap space
     [junit] 	at org.apache.hadoop.mapred.MapTask 
$MapOutputBuffer.<init>(MapTask.java:781)
     [junit] 	at  
org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:350)
     [junit] 	at org.apache.hadoop.mapred.MapTask.run(MapTask.java:307)
     [junit] 	at org.apache.hadoop.mapred.LocalJobRunner 
$Job.run(LocalJobRunner.java:177)

I added a maxmemory attribute to the junit task in the Java build.xml,  
and it seemed to fix the problem:

   <macrodef name="test-runner">
     <attribute name="files.location" />
     <attribute name="tests.pattern" />
     <attribute name="test.dir" default="${test.java.build.dir}" />
     <sequential>
       <junit showoutput="yes"
              printsummary="withOutAndErr"
              haltonfailure="no"
              fork="yes"
	     maxmemory="256m"

I can file a Jira issue and a patch, but seems pretty trivial...

-- Ken


Unable to inject @context from junit test case
Hi,

I am working on a API to expose service using CXF. The strange problem
facing here is, when we deploy as a web-app the UriInfo getting injected
and
everything is working fine.

When we run the Junit test cases, UriBuilder throws NullPointerException
as
the UriInfo holds null. It happens only when we keep the @Context UriInfo
in
an abstract class field or a bean property.

The unit test cases work fine when the UriInfo is been given as a method
param to the APIs we expose.

In Junit test case, we are instantiating JAXRSServerFactoryBean and adding
the resource provider as the service interface. Please help getting
through
this issue.

Thanks,
SK




Running HBase Junit Testcases on local machine
I was trying to run the Juint testcases on my custom Cluster which setup
on
remote machine. I have modified the hbase-site.xml to point to remote hdfs
setup. But when run the unit test case it starts looking in my local host.


Do I need to make changes in any other configuration files. Here is the
output that I am getting when I run TestAdmin Unit testcase. If you see
the
logs it tries to connect on namenode.NameNode: Namenode up at:
127.0.0.1/127.0.0.1:18306

10/07/23 18:39:40 INFO hbase.HBaseTestingUtility: Starting up minicluster
10/07/23 18:39:42 INFO namenode.FSNamesystem:
fsOwner=gagan-pc\gagan,None,Users,ORA_DBA
10/07/23 18:39:42 INFO namenode.FSNamesystem: supergroup=supergroup
10/07/23 18:39:42 INFO namenode.FSNamesystem: isPermissionEnabled=true
10/07/23 18:39:42 INFO common.Storage: Image file of size 104 saved in 0
seconds.
10/07/23 18:39:42 INFO common.Storage: Storage directory
C:\Users\Gagan\Desktop\eclipse-jee-galileo-SR1-win32\ECLIPSE FOR
HBASE\Hbasewrk\HBase\target\build\data\5fa05578-155c-4cb7-88cd-b4e67b278ed4\dfs\name1
has been successfully formatted.
10/07/23 18:39:42 INFO common.Storage: Image file of size 104 saved in 0
seconds.
10/07/23 18:39:42 INFO common.Storage: Storage directory
C:\Users\Gagan\Desktop\eclipse-jee-galileo-SR1-win32\ECLIPSE FOR
HBASE\Hbasewrk\HBase\target\build\data\5fa05578-155c-4cb7-88cd-b4e67b278ed4\dfs\name2
has been successfully formatted.
10/07/23 18:39:43 INFO metrics.RpcMetrics: Initializing RPC Metrics with
hostName=NameNode, port=18306
10/07/23 18:39:43 INFO namenode.NameNode: Namenode up at:
127.0.0.1/127.0.0.1:18306
10/07/23 18:39:43 INFO jvm.JvmMetrics: Initializing JVM Metrics with
processName=NameNode, sessionId=null




Scheduling Junit tests with RunnerScheduler for a concurrent execution
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I came across following site (http://junit.org/node/589) talking about
concurrent execution if junit tests and couldn't resist to give it a try
on the shared project. I used the same configuration in the page shown
(threads=6) and added it to all tests in the shared project. It's 10
seconds faster (64s <-> 54s) what is ~16%.

IMO it's worth to have a closer look at it also when thinking of larger
tests in the apacheds project.

WDOT?
Felix


without concurrency:
[INFO]
- 
Created: (DERBY-4707) convert ShutdownDatabase.java into junit
convert ShutdownDatabase.java into junit