Junit tests for toString()


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Junit tests for toString()

  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, 06:01 AM
  2. Replies: 0
    Last Post: 07-06-2005, 06:06 AM
  3. c# certification tests
    By Monica in forum .NET
    Replies: 2
    Last Post: 06-11-2003, 11:25 AM
  4. C# certification tests
    By Kent in forum .NET
    Replies: 2
    Last Post: 02-03-2003, 10:56 AM
  5. Sun Certified Java Programmer practice tests?
    By Scott Brookhart in forum Java
    Replies: 1
    Last Post: 11-07-2000, 04: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center