You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mi...@nuernberger.de on 2006/09/05 14:17:58 UTC

JUnit4.1 support in Ant 1.7 Beta

Hi,

I have some problems in testing java classes with Junit 4.1 and Ant 1.7 Beta.

The classes to be tested are Singletons written with AspectJ and Java 1.5. The test-classes are pure Junit 4 tests with anotations and without JUnit4TestAdapter.

If I run the ant script I get the exception: "No runnable methods".
But if I run the ant script with the attribute fork="yes" the junit testcase can be executed and I get an "AssertionFailedError".

Can anyone help me finding out, how to start the ant script without VM-forking (attribute fork="yes").


Here is the junit task of my ant-script:

<junit printsummary="on" haltonerror="off"  >
	<formatter type="xml" />
	<classpath>
	 <pathelement path="${classes.dir}" />
		<pathelement path="${test.classes.dir}" />
		<pathelement path="${ant.home}/lib/" />
	</classpath>
	<classpath refid="project.classpath" />

	<batchtest fork="no" todir="${test.report.dir}" >
		<fileset dir="${test.source.dir}">
			<include name="**/*Test*.java" />
			<exclude name="**/*Mock*.java" />
		</fileset>
	</batchtest>
</junit>


Here is the test-case:

public class SingletonTest
{
  @Test 
  public void createSingleton()
  {
    TestMock1 s1 = new TestMock1();
    TestMock1 s2 = new TestMock1();
    
    assertEquals(s1, s2);
    assertTrue(s1.getInvocationTime() == s2.getInvocationTime());
    
    TestMock2 s3 = new TestMock2();
    TestMock2 s4 = new TestMock2();
    
    assertEquals(s3, s4);
    assertTrue(s3.getInvocationTime() == s4.getInvocationTime());
    assertNotSame(s1, s3);
  }
}

and one mock object representatively for the others:

@Singleton
public class TestMock1
{
  protected Long invocationTime = System.currentTimeMillis();
  
  /**
   * Rückgabe der Instanziierungszeit
   * @return long - Timestamp
   */
  public Long getInvocationTime()
  {
    return invocationTime; 
  }

---
Regards
Mirko

Hinweis:
Der Inhalt dieser E-Mail ist ausschließlich für den bezeichneten Empfänger bestimmt und kann vertrauliche Informationen enthalten. Wenn Sie nicht der Empfänger dieser E-Mail oder dessen Vertreter sind, dann senden Sie bitte die E-Mail an den Absender zurück (Antwort-Funktion bzw. reply email). Entfernen Sie bitte danach die Nachricht aus Ihrem System.
This e-mail message including any attachments may contain privileged or confidential information and is for the sole use of the intended recipient(s). If you are not the intended recipient, please immediately return this e-mail message to the sender by reply e-mail, delete the original message and destroy all copies thereof.
MSW 5.1


Re: JUnit4.1 support in Ant 1.7 Beta

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hello Mirko,

I have the impression that no one answered your posting(s). By the way, there is no need to send 3 times the same email.

I would suggest that you create a bug report under http://issues.apache.org/bugzilla . Let's hope that someone will have the time to work on it.

Regards,

Antoine
-------- Original-Nachricht --------
Datum: Tue, 5 Sep 2006 14:17:58 +0200
Von: Mirko.Zieroth@nuernberger.de
An: user@ant.apache.org
Betreff: JUnit4.1 support in Ant 1.7 Beta

> Hi,
> 
> I have some problems in testing java classes with Junit 4.1 and Ant 1.7
> Beta.
> 
> The classes to be tested are Singletons written with AspectJ and Java 1.5.
> The test-classes are pure Junit 4 tests with anotations and without
> JUnit4TestAdapter.
> 
> If I run the ant script I get the exception: "No runnable methods".
> But if I run the ant script with the attribute fork="yes" the junit
> testcase can be executed and I get an "AssertionFailedError".
> 
> Can anyone help me finding out, how to start the ant script without
> VM-forking (attribute fork="yes").
> 
> 
> Here is the junit task of my ant-script:
> 
> <junit printsummary="on" haltonerror="off"  >
> 	<formatter type="xml" />
> 	<classpath>
> 	 <pathelement path="${classes.dir}" />
> 		<pathelement path="${test.classes.dir}" />
> 		<pathelement path="${ant.home}/lib/" />
> 	</classpath>
> 	<classpath refid="project.classpath" />
> 
> 	<batchtest fork="no" todir="${test.report.dir}" >
> 		<fileset dir="${test.source.dir}">
> 			<include name="**/*Test*.java" />
> 			<exclude name="**/*Mock*.java" />
> 		</fileset>
> 	</batchtest>
> </junit>
> 
> 
> Here is the test-case:
> 
> public class SingletonTest
> {
>   @Test 
>   public void createSingleton()
>   {
>     TestMock1 s1 = new TestMock1();
>     TestMock1 s2 = new TestMock1();
>     
>     assertEquals(s1, s2);
>     assertTrue(s1.getInvocationTime() == s2.getInvocationTime());
>     
>     TestMock2 s3 = new TestMock2();
>     TestMock2 s4 = new TestMock2();
>     
>     assertEquals(s3, s4);
>     assertTrue(s3.getInvocationTime() == s4.getInvocationTime());
>     assertNotSame(s1, s3);
>   }
> }
> 
> and one mock object representatively for the others:
> 
> @Singleton
> public class TestMock1
> {
>   protected Long invocationTime = System.currentTimeMillis();
>   
>   /**
>    * Rückgabe der Instanziierungszeit
>    * @return long - Timestamp
>    */
>   public Long getInvocationTime()
>   {
>     return invocationTime; 
>   }
> 
> ---
> Regards
> Mirko
> 
> Hinweis:
> Der Inhalt dieser E-Mail ist ausschließlich für den bezeichneten
> Empfänger bestimmt und kann vertrauliche Informationen enthalten. Wenn Sie nicht
> der Empfänger dieser E-Mail oder dessen Vertreter sind, dann senden Sie
> bitte die E-Mail an den Absender zurück (Antwort-Funktion bzw. reply email).
> Entfernen Sie bitte danach die Nachricht aus Ihrem System.
> This e-mail message including any attachments may contain privileged or
> confidential information and is for the sole use of the intended
> recipient(s). If you are not the intended recipient, please immediately return this
> e-mail message to the sender by reply e-mail, delete the original message and
> destroy all copies thereof.
> MSW 5.1
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org