dcsimg
How do I write a JUnit Test
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   learner_java
Posted On:   Thursday, July 17, 2003 05:41 AM

Hi all! don't really know how to start since i'm new learner to JUnit. I changed my mind..I written a swing code to read information from a file and print to the console using System.out.println() I want to do some practice of JUnit Test program. I want to write a Junit Test program to check to see if my Swing code is run read the file okey and print to the console okey..is that can be done? here is my swing code: import java.io.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.util.Vector; public class ReadEntityFile { priv   More>>

Hi all!

don't really know how to start since i'm new learner to JUnit.

I changed my mind..I written a swing code to read information from a file and print to the console using System.out.println() I want to do some practice of JUnit Test program. I want to write a Junit Test program to check to see if my Swing code is run read the file okey and print to the console okey..is that can be done?

here is my swing code:


import java.io.*;

import javax.swing.*;

import javax.swing.event.*;

import java.awt.event.*;

import java.util.Vector;

public class ReadEntityFile {

private Entity[] entities;

private Entity entity;

private Vector vEntry;

ublic ReadEntityFile() {

entities =getEntity();

for(int i = 0; i < entities.length; i++) {

System.out.println("entitiesitem:" + entities[i].getName());

}

}

public Entity[] getEntity() {

try {

String fn = "c:\test.txt";

File file = new File(fn);


System.out.println("filename:" + file.getPath());

if (!file.exists()) {

System.out.println("File does not exist");

System.exit(0);

}

BufferedReader input = new BufferedReader(new FileReader(file));

String line = "";

vEntry = new Vector();

String name;

while ((line = input.readLine()) != null) {

Entity entity = new Entity();

//get Entity Structure of Entity class

name = line.trim();

entity.setName(name);

vEntry.add(entity);

}

vreturn (Entity[]) vEntry.toArray(new Entity[0]);

} catch (Exception e) {

System.out.println(e.toString());

return new Entity[0];

}

}

public static void main(String[] args) {

ReadEntityFile te = new ReadEntityFile();

}

}

and ofcouse an Entity class, both of them work fine.. but I like to write a Junit Test program..and don't know how to start..can you give me any brainstorms? thanks

   <<Less

Re: How do I write a JUnit Test

Posted By:   Anonymous  
Posted On:   Friday, July 18, 2003 02:39 PM

Take a look at http://www.xp123.com/xplor/xp0001/index.shtml for a good example.
About | Sitemap | Contact