Re: JUnit / newbie question

"Jason Thomas" <[email protected]>
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
> 
> >To get JUnit to run tests written in Nice, I do the following:
> >
> >// TestInterface.java
> >public interface TestInterface {
> >    public void test();
> >}
> >
> >// Test.nice
> >import junit.framework.*;
> >public class Test extends TestCase implements TestInterface {
> >    test() {
> >        assertTrue(true);
> >    }
> >}
> >  
> >Is this the easiest way to run Nice unit tests with JUnit?  It also 
> >gives me a compile error saying that assertTrue is not declared 
> >(assertTrue is a method in TestCase).
> >  
> >
> It's a static method in junit.framework.Assert
> So you'd need to call it Assert.assertTrue(...);

Do you think I should add this to the Wiki documentaion, since it 
differs from Java behaviour, or will it be changed eventually?

> 
> Does JUnit rely on it's own assertion mechanism to be used? What if 
you 
> use Nice's assert?

There's nothing magical about JUnit Assert, it just throws an Error if 
it fails.  I'll look at Nice assert or just pull the methods out on 
JUnit Assert into Nice.

> 
> As you found out, the other difficulty is that JUnit expects to find 
> (static?) test* methods inside the class, and that's not how nicec 
> compiles them. It might in the future, especially for parameterless 
> methods like this.

The test* methods don't need to be static.  It appears the only way to 
be able to call Nice from Java "normally" is to have your Nice class 
extend a Java class and/or implement a Java interface.  Java won't let 
you implement an interface method as static.  So I don't think making 
these methods static is a good idea (or maybe not even possible with 
the byte code verifier...).

> 
> Is it important for you to use JUnit? As far as I understand, this is 
a 
> very simple framework: find the testcases by reflexion, set them up, 
> run, present the results. Am I missing something?

I just like being able to use the JUnit plugin that's integrated into 
Eclipse.  I'm haven't figured out if it's worth the hassle of writing 
these extra interfaces.   Thanks for your help.

-Jason



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.