DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2005
    Posts
    55

    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?

  2. #2
    Join Date
    Aug 2003
    Posts
    313
    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

  1. problem in running junit report
    By yogeshseth in forum Java
    Replies: 0
    Last Post: 07-19-2005, 05:01 AM
  2. Replies: 0
    Last Post: 07-06-2005, 05:06 AM
  3. c# certification tests
    By Monica in forum .NET
    Replies: 2
    Last Post: 06-11-2003, 10:25 AM
  4. C# certification tests
    By Kent in forum .NET
    Replies: 2
    Last Post: 02-03-2003, 09:56 AM
  5. Sun Certified Java Programmer practice tests?
    By Scott Brookhart in forum Java
    Replies: 1
    Last Post: 11-07-2000, 03:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links