Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 29th, 2008, 11:19 PM
kolorowy kolorowy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 27 kolorowy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 37 m 12 sec
Reputation Power: 0
JUnit Test

I want to write simple test unit for my code, but I don't know exactly how to start. Can anyone give me one example how this would work for this code.

Code:
// main class
	public Game() 
		{
	
		setTitle("Game");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		

		// make board
		board = new Board(10,10,20, 20);
		board.setPreferredSize(new Dimension(20*10, 20*10));
		
		// set frame size
		setSize(20*10+100,20*10+20*2+40);

	   
	   // add board to frame
	    add(board,"Center");
	    
	    int r,c;
	    Random rgen = new Random();
	    
	    idriots = new Idriot[10];
	    
	    // make 10 Idriots
	    for(int i=0;i<idriots.length;i++)
	    {
	        idriots[i] = new Idriot(0,0,Color.green);
	    }
	    
	     idots = new Idot[10];
	    
	       // make 10 Idots
	    for(int i=0;i<idots.length;i++)
	    {
	        idots[i] = new Idot(0,0,Color.blue);
	    }
	    
	    // make spaceship
    	spaceship = new Spaceship(0,0,Color.red);
 

		// button panel
		Box buttons = Box.createVerticalBox();
		btnStart = new JButton("Start");
		buttons.add(btnStart);
		btnStart.addActionListener(this);
		
		btnStop = new JButton("Stop");
		buttons.add(btnStop);
		btnStop.addActionListener(this);
		

		// add radio buttons
		
		ButtonGroup bg1 = new ButtonGroup();
		bg1.add(rbManual);
		bg1.add(rbAuto);
		
		buttons.add(rbManual);
		buttons.add(rbAuto);	
		
		ButtonGroup bg2 = new ButtonGroup();
		bg2.add(rbOne);
		bg2.add(rbAll);
		
			
		buttons.add(rbOne);
		buttons.add(rbAll);
		
		buttons.add(new JLabel("Number Idriots:"));
		buttons.add(lblIdroits);
		
       	buttons.add(new JLabel("Number Idots:"));
       	buttons.add(lblIdots);
		
        // move button
        btnMove = new JButton("Move");
		buttons.add(btnMove);
		btnMove.addActionListener(this);
	
		add(buttons,"West");
	
	   setVisible(true);
    }

Reply With Quote
  #2  
Old May 7th, 2008, 03:57 PM
ricardoz ricardoz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Location: Montevideo, Uruguay
Posts: 9 ricardoz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 34 sec
Reputation Power: 0
JUnit tests are meant to execute each (public) method of your classes with different combination of parameters to verify they behave as they should.

Since the code you posted has no methods it doesn't seem JUnit is the tool you need.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > JUnit Test


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT