Results 1 to 3 of 3
Thread: Adding tests to a Java class
- 01-11-2012, 03:22 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 1
- Rep Power
- 0
Adding tests to a Java class
Hi,
I have been given a Java program, and been asked to write a set of tests for one of the classes, but it's been a long time since I've done any programming, and I'm a bit unsure of where to start...
This is the class that I have been asked to write tests for:
There a couple of things I'm not sure about, i.e. should I add the tests to this class, or should I create a separate class to do the testing?Java Code:package uk.ac.aber.dcs.cs31310.qs; public class Question { private String id; private String text; public Question(String id, String text) { this.id = id; this.text = text; } public String getId() { return id; } public String getText() { return text; } public void setText(String text) { this.text = text; } @Override public boolean equals(Object other) { if(other instanceof Question) { Question otherQuestion = (Question)other; return this.id.equals(otherQuestion.id); } return false; } }
Also, how would I then go about testing each of the methods in the class?
The task description is simply:
Write a set of tests for the Question class. You should do this for all of the methods that are currently in the Question class1. If you identify any bugs with the code, you should fix the bugs and state what you have fixed in your report.
- 01-11-2012, 03:32 PM #2
Re: Adding tests to a Java class
You'd test it by answering the question: does each method do what it's supposed to do? So your first step would be to write out, in your own words, what each method should do. What is true before the method is called? What is true afterwards? Then write code that tests those assumptions.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-11-2012, 04:57 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Adding tests to a Java class
And the testing code would be in a different class.
It would create an instance of Question and then have tests that will call a method with some parameter or other and then check whether the question object has done the correct thing (ie the data has been changed correctly).
Similar Threads
-
help adding to array from another class
By Grid_iso in forum New To JavaReplies: 0Last Post: 05-09-2011, 10:00 AM -
Adding 2 Implements to the class
By jboy in forum New To JavaReplies: 2Last Post: 10-23-2009, 05:19 AM -
Take Java skills assessments- assess your skills and provide insight on new tests
By michelle in forum Jobs OfferedReplies: 8Last Post: 08-11-2009, 03:57 PM -
Adding a new class to a jar file
By Raul Menendez in forum New To JavaReplies: 2Last Post: 08-21-2008, 04:52 PM -
Test Advisory Panel-Telecommute- Test your Java skills + share insights on Java tests
By michelle in forum Jobs OfferedReplies: 0Last Post: 04-05-2008, 12:38 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks