Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Technology Project and PMC » JUnit question in Eclipse
JUnit question in Eclipse [message #60290] Tue, 23 December 2003 17:59 Go to next message
Eclipse User
Originally posted by: no.spam.com

I'm in the process of trying to learn JUnit, and integrate some tests
into one of my applications.

The problem that I am having is that when I run this as a JUnit test
from Eclipse, it executes my setUp() method once for every method that
starts with test... instead of just calling it once for all tests in
this class. My actual setUp method is kind of expensive, so I don't
want to do it multiple times.

Apologies if this is off topic, or if I am missing something really
simple... but I can't seem to figure it out. Any help would be
appreciated. My basic class structure is below.

Thanks,

Dan

My test class currently looks something like this:

public class TestBrowserOperations extends TestCase
{
private BrowserOperations boi_;

public static void main(String[] args)
{
}

protected void setUp() throws Exception
{
boi_ = //do the setup...
}

protected void tearDown() throws Exception
{
boi_ = null;
super.tearDown();
}


public void testGetCTSVersion() throws Exception
{
assertNotNull(boi_.getCTSVersion());
}

public void testGetServiceDescription() throws Exception
{
assertNotNull(boi_.getServiceDescription());
}
}
Re: JUnit question in Eclipse [message #60314 is a reply to message #60290] Tue, 23 December 2003 20:07 Go to previous messageGo to next message
Eclipse User
Originally posted by: davidoii.hotmail.com

That is not an Eclipse issue; that is how JUnit works. The setup method
is supposed to be called before each test is run. The setup method is
used to put the test grounds into a known state. But if you really only
want to call it once (not recommended), you can create an internal-class
and put your test methods there. Then the setup() function will only be
called once (checkout the JUnit FAQ - junit.org - for more info on that).

Good luck!
David

Dan Armbrust wrote:
> I'm in the process of trying to learn JUnit, and integrate some tests
> into one of my applications.
>
> The problem that I am having is that when I run this as a JUnit test
> from Eclipse, it executes my setUp() method once for every method that
> starts with test... instead of just calling it once for all tests in
> this class. My actual setUp method is kind of expensive, so I don't
> want to do it multiple times.
>
> Apologies if this is off topic, or if I am missing something really
> simple... but I can't seem to figure it out. Any help would be
> appreciated. My basic class structure is below.
>
> Thanks,
>
> Dan
>
> My test class currently looks something like this:
>
> public class TestBrowserOperations extends TestCase
> {
> private BrowserOperations boi_;
>
> public static void main(String[] args)
> {
> }
>
> protected void setUp() throws Exception
> {
> boi_ = //do the setup...
> }
>
> protected void tearDown() throws Exception
> {
> boi_ = null;
> super.tearDown();
> }
>
>
> public void testGetCTSVersion() throws Exception
> {
> assertNotNull(boi_.getCTSVersion());
> }
>
> public void testGetServiceDescription() throws Exception
> {
> assertNotNull(boi_.getServiceDescription());
> }
> }
Re: JUnit question in Eclipse *off topic* [message #60338 is a reply to message #60314] Tue, 23 December 2003 21:36 Go to previous messageGo to next message
Eclipse User
Originally posted by: no.spam.com

Thanks. I set up a new class to hold a single instance of my object
that is expensive to build... so it can be reused. This fixed it... but
it seems like such a hack.

What is the accepted way to do something expensive (like create
connections to an ldap server, read prefererences from disk, etc) and
reuse this in all of the test cases?

This seems like it would be a pretty common issue. I guess I should
probably move over to the JUnit mailing lists.

Thanks,

Dan

David Owens II wrote:

> That is not an Eclipse issue; that is how JUnit works. The setup method
> is supposed to be called before each test is run. The setup method is
> used to put the test grounds into a known state. But if you really only
> want to call it once (not recommended), you can create an internal-class
> and put your test methods there. Then the setup() function will only be
> called once (checkout the JUnit FAQ - junit.org - for more info on that).
>
> Good luck!
> David
>
> Dan Armbrust wrote:
>
>> I'm in the process of trying to learn JUnit, and integrate some tests
>> into one of my applications.
>>
>> The problem that I am having is that when I run this as a JUnit test
>> from Eclipse, it executes my setUp() method once for every method that
>> starts with test... instead of just calling it once for all tests in
>> this class. My actual setUp method is kind of expensive, so I don't
>> want to do it multiple times.
>>
>> Apologies if this is off topic, or if I am missing something really
>> simple... but I can't seem to figure it out. Any help would be
>> appreciated. My basic class structure is below.
>>
>> Thanks,
>>
>> Dan
>>
>> My test class currently looks something like this:
>>
>> public class TestBrowserOperations extends TestCase
>> {
>> private BrowserOperations boi_;
>>
>> public static void main(String[] args)
>> {
>> }
>>
>> protected void setUp() throws Exception
>> {
>> boi_ = //do the setup...
>> }
>>
>> protected void tearDown() throws Exception
>> {
>> boi_ = null;
>> super.tearDown();
>> }
>>
>>
>> public void testGetCTSVersion() throws Exception
>> {
>> assertNotNull(boi_.getCTSVersion());
>> }
>>
>> public void testGetServiceDescription() throws Exception
>> {
>> assertNotNull(boi_.getServiceDescription());
>> }
>> }
Re: JUnit question in Eclipse *off topic* [message #60362 is a reply to message #60338] Wed, 24 December 2003 01:55 Go to previous messageGo to next message
Eclipse User
Originally posted by: davidoii.hotmail.com

You're right, it is a hack and it's not considered good testing style.
If you want to create a connection or something of the sort, just put it
in the constructor of the test class. This will be called only once.

Hope that helps!
David

Dan Armbrust wrote:
> Thanks. I set up a new class to hold a single instance of my object
> that is expensive to build... so it can be reused. This fixed it... but
> it seems like such a hack.
>
> What is the accepted way to do something expensive (like create
> connections to an ldap server, read prefererences from disk, etc) and
> reuse this in all of the test cases?
>
> This seems like it would be a pretty common issue. I guess I should
> probably move over to the JUnit mailing lists.
>
> Thanks,
>
> Dan
>
> David Owens II wrote:
>
>> That is not an Eclipse issue; that is how JUnit works. The setup
>> method is supposed to be called before each test is run. The setup
>> method is used to put the test grounds into a known state. But if you
>> really only want to call it once (not recommended), you can create an
>> internal-class and put your test methods there. Then the setup()
>> function will only be called once (checkout the JUnit FAQ - junit.org
>> - for more info on that).
>>
>> Good luck!
>> David
>>
>> Dan Armbrust wrote:
>>
>>> I'm in the process of trying to learn JUnit, and integrate some tests
>>> into one of my applications.
>>>
>>> The problem that I am having is that when I run this as a JUnit test
>>> from Eclipse, it executes my setUp() method once for every method
>>> that starts with test... instead of just calling it once for all
>>> tests in this class. My actual setUp method is kind of expensive, so
>>> I don't want to do it multiple times.
>>>
>>> Apologies if this is off topic, or if I am missing something really
>>> simple... but I can't seem to figure it out. Any help would be
>>> appreciated. My basic class structure is below.
>>>
>>> Thanks,
>>>
>>> Dan
>>>
>>> My test class currently looks something like this:
>>>
>>> public class TestBrowserOperations extends TestCase
>>> {
>>> private BrowserOperations boi_;
>>>
>>> public static void main(String[] args)
>>> {
>>> }
>>>
>>> protected void setUp() throws Exception
>>> {
>>> boi_ = //do the setup...
>>> }
>>>
>>> protected void tearDown() throws Exception
>>> {
>>> boi_ = null;
>>> super.tearDown();
>>> }
>>>
>>>
>>> public void testGetCTSVersion() throws Exception
>>> {
>>> assertNotNull(boi_.getCTSVersion());
>>> }
>>>
>>> public void testGetServiceDescription() throws Exception
>>> {
>>> assertNotNull(boi_.getServiceDescription());
>>> }
>>> }
Re: JUnit question in Eclipse *off topic* [message #60984 is a reply to message #60338] Thu, 15 January 2004 00:05 Go to previous message
Eclipse User
Originally posted by: rtayek.no.spam.freightgate.com

"Dan Armbrust" <no@spam.com> wrote in message
news:bsach6$n2d$1@eclipse.org...
> Thanks. I set up a new class to hold a single instance of my object
> that is expensive to build... so it can be reused. This fixed it... but
> it seems like such a hack. ...
> ...This seems like it would be a pretty common issue. I guess I should
> probably move over to the JUnit mailing lists.
>
....
yes, iirc, it was a recent thread and perhaps a class was uploaded. maybe
try the archives.
Re: JUnit question in Eclipse [message #596248 is a reply to message #60290] Tue, 23 December 2003 20:07 Go to previous message
Eclipse User
Originally posted by: davidoii.hotmail.com

That is not an Eclipse issue; that is how JUnit works. The setup method
is supposed to be called before each test is run. The setup method is
used to put the test grounds into a known state. But if you really only
want to call it once (not recommended), you can create an internal-class
and put your test methods there. Then the setup() function will only be
called once (checkout the JUnit FAQ - junit.org - for more info on that).

Good luck!
David

Dan Armbrust wrote:
> I'm in the process of trying to learn JUnit, and integrate some tests
> into one of my applications.
>
> The problem that I am having is that when I run this as a JUnit test
> from Eclipse, it executes my setUp() method once for every method that
> starts with test... instead of just calling it once for all tests in
> this class. My actual setUp method is kind of expensive, so I don't
> want to do it multiple times.
>
> Apologies if this is off topic, or if I am missing something really
> simple... but I can't seem to figure it out. Any help would be
> appreciated. My basic class structure is below.
>
> Thanks,
>
> Dan
>
> My test class currently looks something like this:
>
> public class TestBrowserOperations extends TestCase
> {
> private BrowserOperations boi_;
>
> public static void main(String[] args)
> {
> }
>
> protected void setUp() throws Exception
> {
> boi_ = //do the setup...
> }
>
> protected void tearDown() throws Exception
> {
> boi_ = null;
> super.tearDown();
> }
>
>
> public void testGetCTSVersion() throws Exception
> {
> assertNotNull(boi_.getCTSVersion());
> }
>
> public void testGetServiceDescription() throws Exception
> {
> assertNotNull(boi_.getServiceDescription());
> }
> }
Re: JUnit question in Eclipse *off topic* [message #596259 is a reply to message #60314] Tue, 23 December 2003 21:36 Go to previous message
Dan Armbrust is currently offline Dan Armbrust
Messages: 8
Registered: July 2009
Junior Member
Thanks. I set up a new class to hold a single instance of my object
that is expensive to build... so it can be reused. This fixed it... but
it seems like such a hack.

What is the accepted way to do something expensive (like create
connections to an ldap server, read prefererences from disk, etc) and
reuse this in all of the test cases?

This seems like it would be a pretty common issue. I guess I should
probably move over to the JUnit mailing lists.

Thanks,

Dan

David Owens II wrote:

> That is not an Eclipse issue; that is how JUnit works. The setup method
> is supposed to be called before each test is run. The setup method is
> used to put the test grounds into a known state. But if you really only
> want to call it once (not recommended), you can create an internal-class
> and put your test methods there. Then the setup() function will only be
> called once (checkout the JUnit FAQ - junit.org - for more info on that).
>
> Good luck!
> David
>
> Dan Armbrust wrote:
>
>> I'm in the process of trying to learn JUnit, and integrate some tests
>> into one of my applications.
>>
>> The problem that I am having is that when I run this as a JUnit test
>> from Eclipse, it executes my setUp() method once for every method that
>> starts with test... instead of just calling it once for all tests in
>> this class. My actual setUp method is kind of expensive, so I don't
>> want to do it multiple times.
>>
>> Apologies if this is off topic, or if I am missing something really
>> simple... but I can't seem to figure it out. Any help would be
>> appreciated. My basic class structure is below.
>>
>> Thanks,
>>
>> Dan
>>
>> My test class currently looks something like this:
>>
>> public class TestBrowserOperations extends TestCase
>> {
>> private BrowserOperations boi_;
>>
>> public static void main(String[] args)
>> {
>> }
>>
>> protected void setUp() throws Exception
>> {
>> boi_ = //do the setup...
>> }
>>
>> protected void tearDown() throws Exception
>> {
>> boi_ = null;
>> super.tearDown();
>> }
>>
>>
>> public void testGetCTSVersion() throws Exception
>> {
>> assertNotNull(boi_.getCTSVersion());
>> }
>>
>> public void testGetServiceDescription() throws Exception
>> {
>> assertNotNull(boi_.getServiceDescription());
>> }
>> }
Re: JUnit question in Eclipse *off topic* [message #596266 is a reply to message #60338] Wed, 24 December 2003 01:55 Go to previous message
Eclipse User
Originally posted by: davidoii.hotmail.com

You're right, it is a hack and it's not considered good testing style.
If you want to create a connection or something of the sort, just put it
in the constructor of the test class. This will be called only once.

Hope that helps!
David

Dan Armbrust wrote:
> Thanks. I set up a new class to hold a single instance of my object
> that is expensive to build... so it can be reused. This fixed it... but
> it seems like such a hack.
>
> What is the accepted way to do something expensive (like create
> connections to an ldap server, read prefererences from disk, etc) and
> reuse this in all of the test cases?
>
> This seems like it would be a pretty common issue. I guess I should
> probably move over to the JUnit mailing lists.
>
> Thanks,
>
> Dan
>
> David Owens II wrote:
>
>> That is not an Eclipse issue; that is how JUnit works. The setup
>> method is supposed to be called before each test is run. The setup
>> method is used to put the test grounds into a known state. But if you
>> really only want to call it once (not recommended), you can create an
>> internal-class and put your test methods there. Then the setup()
>> function will only be called once (checkout the JUnit FAQ - junit.org
>> - for more info on that).
>>
>> Good luck!
>> David
>>
>> Dan Armbrust wrote:
>>
>>> I'm in the process of trying to learn JUnit, and integrate some tests
>>> into one of my applications.
>>>
>>> The problem that I am having is that when I run this as a JUnit test
>>> from Eclipse, it executes my setUp() method once for every method
>>> that starts with test... instead of just calling it once for all
>>> tests in this class. My actual setUp method is kind of expensive, so
>>> I don't want to do it multiple times.
>>>
>>> Apologies if this is off topic, or if I am missing something really
>>> simple... but I can't seem to figure it out. Any help would be
>>> appreciated. My basic class structure is below.
>>>
>>> Thanks,
>>>
>>> Dan
>>>
>>> My test class currently looks something like this:
>>>
>>> public class TestBrowserOperations extends TestCase
>>> {
>>> private BrowserOperations boi_;
>>>
>>> public static void main(String[] args)
>>> {
>>> }
>>>
>>> protected void setUp() throws Exception
>>> {
>>> boi_ = //do the setup...
>>> }
>>>
>>> protected void tearDown() throws Exception
>>> {
>>> boi_ = null;
>>> super.tearDown();
>>> }
>>>
>>>
>>> public void testGetCTSVersion() throws Exception
>>> {
>>> assertNotNull(boi_.getCTSVersion());
>>> }
>>>
>>> public void testGetServiceDescription() throws Exception
>>> {
>>> assertNotNull(boi_.getServiceDescription());
>>> }
>>> }
Re: JUnit question in Eclipse *off topic* [message #596420 is a reply to message #60338] Thu, 15 January 2004 00:05 Go to previous message
Eclipse User
Originally posted by: rtayek.no.spam.freightgate.com

"Dan Armbrust" <no@spam.com> wrote in message
news:bsach6$n2d$1@eclipse.org...
> Thanks. I set up a new class to hold a single instance of my object
> that is expensive to build... so it can be reused. This fixed it... but
> it seems like such a hack. ...
> ...This seems like it would be a pretty common issue. I guess I should
> probably move over to the JUnit mailing lists.
>
....
yes, iirc, it was a recent thread and perhaps a class was uploaded. maybe
try the archives.
Previous Topic:jdt class not resolved in PDE java editor
Next Topic:Java 1.5
Goto Forum:
  


Current Time: Mon Oct 20 22:44:46 GMT 2014

Powered by FUDForum. Page generated in 0.03354 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software