Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Testing testcase in Junit3 using treemap

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb Testing testcase in Junit3 using treemap

    Hello Everybody,

    I am beginner in Java and facing one problem while testing junit3 testcase using treemap.

    The code :
    ===========================
    package sampleJunit3;

    import java.util.TreeMap;
    import org.junit.*;
    import static org.junit.Assert.*;
    import junit.framework.TestCase;

    public class TestSimpleTreemap3 extends TestCase {
    public void Trmp(){
    TreeMap<String, String> hm = new TreeMap<String, String>();

    hm.put("100","Amit");
    assertEquals("Amit",hm.get("100"));
    }
    }
    =============================

    While running as a Junit Test, test getting failed with error " Test Class not found in selected project".

    Tried to search in web for the solution , but nothing is working. Can any one please help me to solve the problem.

    Thank you very much for your support and cooperation.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,659
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: Testing testcase in Junit3 using treemap

    Each test method needs the annotation:
    @Test
    before it.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Testing testcase in Junit3 using treemap

    Thanks aussiemcgr, but I am testing in Junit 3 and annotation required in Junit 4.

  4. #4
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Testing testcase in Junit3 using treemap

    JUnit 3 test method names require a "test" prefix in order for JUnit's test runner to be able to find them. Therefore all you need to do is to rename your Trmp() method to testTrmp(). (Btw, the usual convention for Java method names is to start them with a lowercase character.)

  5. The Following 2 Users Say Thank You to jashburn For This Useful Post:

    GregBrannon (April 23rd, 2014), saoley (April 23rd, 2014)

  6. #5
    Junior Member
    Join Date
    Apr 2014
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Testing testcase in Junit3 using treemap

    Quote Originally Posted by jashburn View Post
    JUnit 3 test method names require a "test" prefix in order for JUnit's test runner to be able to find them. Therefore all you need to do is to rename your Trmp() method to testTrmp(). (Btw, the usual convention for Java method names is to start them with a lowercase character.)
    Woww, jashburn, This is amezing. My code is working now. THANKS a LOT.
    Just to mentioned here , there are two ways to write name of method in junit3 . Either you can start with "test" name or you can use private .
    I have tried both ways till yesterday, dont know why it didn't work. But after you mentioned , again, I tried with "test" and now it works....hehe.....

Similar Threads

  1. Help with main method TestCase.java
    By Jawa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 1st, 2014, 11:39 AM
  2. Java automated testing tools for Unit testing
    By rameezraja in forum Member Introductions
    Replies: 2
    Last Post: April 14th, 2012, 08:51 AM
  3. How TreeMap does what it does.
    By meathead in forum Java Theory & Questions
    Replies: 2
    Last Post: July 21st, 2011, 04:20 PM
  4. Junit3 error: Implicit super constructor TestCase() is not visible
    By albertkao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 21st, 2011, 11:53 AM
  5. treemap Duplicates
    By debug in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 6th, 2010, 10:52 AM