Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Junit - Testing a View
Junit - Testing a View [message #314575] Wed, 18 April 2007 00:09 Go to next message
Eclipse UserFriend
Originally posted by: swetha.yahoo.co.in

Hi,

I have a tree view, I have some actions which are added to the
ToolbarManager as follows,

IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
mgr.add(exitAction);
When I am testing this method using JUnit, getViewSite() is coming as a
null and getting NullPointerException,

How can I get the getViewSite() not null;

Pls help me...

Thanks,
Swetha
Re: Junit - Testing a View [message #314680 is a reply to message #314575] Thu, 19 April 2007 08:40 Go to previous messageGo to next message
Eclipse UserFriend
1) make sure you are running a JUnit plug-in test instead of a normal
JUnit test

2) make sure you open a workbench window and either find the view or
show it if it is not already visible.

Later,
PW
Re: Junit - Testing a View [message #314706 is a reply to message #314680] Fri, 20 April 2007 05:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: swetha.yahoo.co.in

Hi,

Thanks for the reply.....I did the same but still getSite(),
getViewSite() are null only....

I am running it as a workbench only.. the workbench is closed after
executing all the test cases..

Thanks,
Swetha
Re: Junit - Testing a View [message #314717 is a reply to message #314706] Fri, 20 April 2007 09:23 Go to previous messageGo to next message
Eclipse UserFriend
Please post the snippet that is your JUnit test method. The important
code ... how are you find the workbench window? How are you finding
your open view?


PW
Re: Junit - Testing a View [message #314752 is a reply to message #314717] Mon, 23 April 2007 00:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: swetha.yahoo.co.in

Hi,

This is the test method..

public class CustomerViewTest extends TestCase
{
CustomerView custView;

@Before
public void setUp() throws Exception
{
custView = new CustomerView();

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().
showView("com.sequenom.everest.ui.CustomerView");
}

@After
public void tearDown() throws Exception
{

}
// Testing
@Test
public void testCreateTreeWidget()
{
custView.createWidget(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell());
Assert.assertNotNull(custView.tree);
MouseEvent g;
custView.tree.getTree();
}

}


When I am testing the createWidget() method in CustomerView class , the
NullPointerExcepton is coming at the line,

getSite().setSelectionProvider(tree);

getSite() is coming as null;


Thanks,
Swetha
Re: Junit - Testing a View [message #314787 is a reply to message #314752] Tue, 24 April 2007 01:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: swetha.yahoo.co.in

Hi Paul,

Can u please help me why I am unable to access getViewSite() and
getSite()...

Thanks,
Swetha
Re: Junit - Testing a View [message #314812 is a reply to message #314752] Tue, 24 April 2007 12:25 Go to previous messageGo to next message
Eclipse UserFriend
Swetha wrote:
> Hi,
>
> This is the test method..
>
> public class CustomerViewTest extends TestCase
> {
> CustomerView custView;
>
> @Before
> public void setUp() throws Exception
> {
> custView = new CustomerView();

This is the part that won't work.


In your test, use IWorkbenchPage#findView("your.view.id") to get custView

Later,
PW
Re: Junit - Testing a View [message #314876 is a reply to message #314812] Thu, 26 April 2007 06:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: swetha.yahoo.co.in

Hi,

Its not working,

I have placed the following ,

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().findView( "com.sequenom.everest.ui.CustomerView");


Still it getSite() and getViewSite() is null

Thanks,
Swetha
Re: Junit - Testing a View [message #314888 is a reply to message #314876] Thu, 26 April 2007 10:07 Go to previous messageGo to next message
Eclipse UserFriend
Show us the snippet of code ... i.e. your setup and test ... the code
you wrote works fine when I run it :-)


PW
Re: Junit - Testing a View [message #314907 is a reply to message #314888] Fri, 27 April 2007 00:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: swetha.yahoo.co.in

Hi,

The following is the method I am testing,

public void createWidget(Composite parent)
{
tree = new TreeViewer(parent, SWT.BORDER);
GlobalVariablesClass.modifier = new TreeCellModifier(tree);
tree.setCellModifier(GlobalVariablesClass.modifier);

tree.setColumnProperties(new String[] { "ProjectWidget" });

tree.setCellEditors(new CellEditor[] { new TextCellEditor(tree
.getTree()) });


getSite().setSelectionProvider(tree);

// Adding Actions to context menu,Menubar and Toolbar


}


And the corresponding test method in JUnit is,


public class CustomerViewTest extends TestCase
{
CustomerView custView;

@Before
public void setUp() throws Exception
{
super.setUp();
custView = new CustomerView();

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().findView( "com.sequenom.everest.ui.CustomerView");

}

@After
public void tearDown() throws Exception
{
super.tearDown();

}

@Test
public void testGetTreeWidget()
{
custView.createWidget(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell());

Assert.assertNotNull(custView.tree);
}

}

}


The line getSite().setSelectionProvider(tree) , getSite() is coming as
null and causing NullPointerException

Thanks,
Swetha
Re: Junit - Testing a View [message #314918 is a reply to message #314907] Fri, 27 April 2007 07:19 Go to previous messageGo to next message
Eclipse UserFriend
Swetha wrote:
> Hi,

> {
> super.setUp();
> custView = new CustomerView();

I told you this wouldn't work.


What I mean is something like:
public void testGetTreeWidget() {
custView =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().showView( "com.sequenom.everest.ui.CustomerView");
Assert.assertNotNull(custView.tree);
}

Later,
PW
Re: Junit - Testing a View [message #314919 is a reply to message #314918] Fri, 27 April 2007 08:16 Go to previous message
Eclipse UserFriend
Originally posted by: swetha.yahoo.co.in

Hi,

got it .. Thank you very much...

Regards,
Swetha
Previous Topic:Line number shown by default
Next Topic:Organize imports - Bug???
Goto Forum:
  


Current Time: Tue May 13 07:51:40 EDT 2025

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

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

Back to the top