File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes JUnit testing problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit testing problem" Watch "JUnit testing problem" New topic
Author

JUnit testing problem

Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
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

Joined: Oct 27, 2005
Posts: 19693
    
  20

Moving to Testing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
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

Joined: Jul 11, 2001
Posts: 14112
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.);


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Maurice Le Chat
Greenhorn

Joined: Jan 20, 2009
Posts: 18
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!


SCJP 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit testing problem