• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How test Interfaces and Abstract classes

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would like to know how to test Interfaces and Abstract classes. Because my module contains 6 interfaces and 3 abstract classes and 2 ordinary java files. In these 2 files most of the method's return type is void. Most of the Abstract class methods are very simple and depends on private and protected. How to write test cases in this case.

Regards
Prashanth.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at http://www.placebosoft.com/abstract-test.html

If you need more specific advice, a code example might help.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just for fun, as an alternative or a supplement you might want to look at Programming with Contracts in Java, in the latest JavaRanch Journal.
 
ambati prashanth
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Take a look at http://www.placebosoft.com/abstract-test.html

If you need more specific advice, a code example might help.



Hi,
the examples in this web pageare, I applied in my program. It is giving error as no test case found. I extended TestCase by an abstract class as they shown.If I remove that abstract and put class in that place it won't give that error.

regards
Prashnth

[ August 16, 2005: Message edited by: ambati prashanth ]
[ August 16, 2005: Message edited by: ambati prashanth ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please show us your code.
 
ambati prashanth
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/**

As I shown below I given abstract for a class which extends TestCase class.
But in the link you given they given same.Here at confused symbols I given abstract.I got error as "No JUnit Test Found". What may be the problem
*/

package com.ejbpro;

import junit.framework.TestCase;

import com.mobiapps.business.framework.MobiDTO;
import com.mobiapps.business.framework.MobiSession;
import com.mobiapps.mtrak.drivers.*;


public abstract class DriverStatelessRemoteTest extends TestCase
{

protected void tearDown() throws Exception
{

}
private DriverStatelessRemote driver;

public MobiDTO dto;

public static MobiSession session = new MobiSession();

public DriverStatelessRemoteTest(String name)
{
super(name);
}
public final void setUp() throws Exception
{
driver=createDriverStatelessRemote();
assertNotNull("It should'nt be null",driver);
}

public abstract DriverStatelessRemote createDriverStatelessRemote() throws Exception;



public void testAdd() throws Exception
{
boolean x=driver.add(dto,session);
System.out.println("Value is: "+x);
}

}
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, so far this looks good. No you need a concrete test case class that extends your abstract one and provides the object under test. Do you have that one, too?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I dont have that one. What shall I do now?
Tell me how to do.

Thanks in Advance
Bala
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you can't really test interfaces and abstract classes, simply because you can't instantiate them. What you can do is provide an abstract testcase that you then complete to a concrete testcase for every concrete subclass.

That is, if you have - for example - a MyDriverStatelessRemote class, you'd also have a MyDriverStatelessRemoteTest class that implements the createDriverStatelessRemote method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic