File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JUnit testing problem

 
Ben Hultin
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building a JUnit test to check a method and the value it is returning bc it doesnt seem to be returning anything so far. So its not test driven development, I prefer to save my frustrations for the code that does the work until I need to find out why the code isnt working.

This is the test I am working on...



This is the method I am trying to test...




I have the source class titled as:

public class CodeLibraryView extends FrameView {

also I created the object for the variable msg

private Object msg;


The error I am getting is as follows:

Non-static method cant be reference from a static context <identifier> expected


I appreciate any help in the matter
Thanks a lot
 
Rob Spoor
Sheriff
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Testing.
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben:

From the information provided, I would guess that the problem you're encountering doesn't have anything to do with the code that you posted. I think you're trying to call a non-static method from a static instance.

John.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John de Michele wrote:Ben:

From the information provided, I would guess that the problem you're encountering doesn't have anything to do with the code that you posted. I think you're trying to call a non-static method from a static instance.

John.


And that call is actually in the code posted:

CodeLibraryView.right_align_comboMouseClicked(java.awt.event.);
 
Maurice Le Chat
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, cool down, JUnit helps a lot!

Your test fails, because your method under test does return nothing (void) hence do not expect to get something back!

But your method sets the Text of a field! Hence go to read back the field with the text set!

You can not access this field? Victory! JUnit helped you to find out this very early and did a very good job. You don't need access to this field but only for test? Think again what you need!

Beside have a look at http://easytesting.org/swing/wiki/pmwiki.php

For automatic testing of UI this extends JUnit in a very powerful manner!

Have fun!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic