-
Junit tests for toString()
I want to create a toString test but i have alot of descriptive text inside my string and two strings will never be the same as shown below:
public String toString(){
return ("Name: " + fname + ", " + lname + "Product: " + product);
}
aCustomer.toString("Andrew", "Bogart", "Coke");
It will not be the sane as name and product are not included.
I am currently printing out the toString extracted from customer class and using println to show the expected result as shown below
System.out.println("Expected " + "Name :" + "Andrew" + ", " + "Boggart" + " Product: " + Coke);
System.out.println(aCustomer.toString("Andrew", "Bogart", "Coke"));
Does anyone have a better way to test the toString method using Junit tests?
-
Pattern matching is usually a viable alternative, if the version of java that you are using supports it. Check out the Regular Expression tutorial at: http://java.sun.com/docs/books/tutorial/extra/regex/
Hope this helps.
~evlich
Similar Threads
-
By yogeshseth in forum Java
Replies: 0
Last Post: 07-19-2005, 05:01 AM
-
By yogeshseth in forum Java
Replies: 0
Last Post: 07-06-2005, 05:06 AM
-
Replies: 2
Last Post: 06-11-2003, 10:25 AM
-
Replies: 2
Last Post: 02-03-2003, 09:56 AM
-
By Scott Brookhart in forum Java
Replies: 1
Last Post: 11-07-2000, 03:08 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks