Menu

Some JFCUnit questions

Help
2005-06-17
2013-04-09
  • Gaurav Tanna

    Gaurav Tanna - 2005-06-17

    Hi all,

    Can anyone suggest me how do I go about testing right clicks ? I have a JTree & I can find it. But how do I right click on the tree nodes ? Also I have one more problem. I have multiple tests in my code. For eg. below. But when I run my tests using the junit textui runner only 1 ie. testMain() is executed. testMenu() is not executed at all. Can anyone suggest me how to make all test run ?

    Thanks,
    Gaurav

    public class AdminClientTest extends JFCTestCase {
        private NewUserInputDlg m_NewUserInputDlg;
        private AdminClient m_AdminClient;
        private CtrlPanel ctrlPanel = null;
        private JFCTestHelper helper;

        public AdminClientTest (String name){
            super (name);
        }

        protected void setUp() throws Exception{
            super.setUp();
            helper = new JFCTestHelper();

            String[] args = new String[2];
            args[0] = new String("admin");
            args[1] = new String("admin");

            m_AdminClient = new AdminClient(new JFrame(),"",new AdminUser());

            m_AdminClient.main(args);
        }

        protected void tearDown() throws Exception{
            TestHelper.cleanUp(this);
            super.tearDown();
        }

        // Tests ....
        public void testMain(){
            List windows;

            windows = helper.getWindows();
            assertEquals("number of windows showing is incorrect", 1, windows.size());

            JMenuItemFinder finder;

            finder = new JMenuItemFinder("file",true);

            JMenuItem fileMenu = (JMenuItem) finder.find();
            assertNotNull( "Could not find the file menu", fileMenu );

            finder.setText("Help");
            JMenuItem helpMenu = (JMenuItem) finder.find();
            assertNotNull( "Could not find the help menu", helpMenu );

            helper.enterClickAndLeave( new MouseEventData(this, helpMenu));

            finder.setText("help topics");
            JMenuItem helpTopicsMenu = (JMenuItem) finder.find();
            assertNotNull( "Could not find the help menu", helpTopicsMenu );
            helper.enterClickAndLeave( new MouseEventData(this, helpTopicsMenu));

           

            final JTree myJTree = (JTree)helper.findComponent(JTree.class, 0);
            assertNotNull(myJTree);

            helper.enterClickAndLeave(new JTreeMouseEventData(this, myJTree, "AXSVision Security", 2, 3000));
        }

        public void testMenu(){

            System.out.println("Test for finding menus");

            JMenuItemFinder finder;

            finder = new JMenuItemFinder("file",true);

            JMenuItem fileMenu = (JMenuItem) finder.find();
            assertNotNull( "Could not find the file menu", fileMenu );

            finder.setText("Help");
            JMenuItem helpMenu = (JMenuItem) finder.find();
            assertNotNull( "Could not find the help menu", helpMenu );

            helper.enterClickAndLeave( new MouseEventData(this, helpMenu));

            finder.setText("help topics");
            JMenuItem helpTopicsMenu = (JMenuItem) finder.find();
            assertNotNull( "Could not find the help menu", helpTopicsMenu );
            helper.enterClickAndLeave( new MouseEventData(this, helpTopicsMenu));

        }

    }

     
    • Gaurav Tanna

      Gaurav Tanna - 2005-06-17

      OK, I figured out the right click issue. But I am still not able to run multiple tests. Even the JUnit plugin in IntelliJ IDE doesnt run multiple tests although it detects that there are more than one tests.

      Thanks,
      Gaurav

       
      • Ritesh Trivedi

        Ritesh Trivedi - 2005-06-17

        Gaurav,

        There are multiple ways of doing that. You can specify the class name in the textrunner run method is one of them. The other ways are implementing static method which returns suite and add all the tests that you want run.

        Here is the link from junit.org
        http://junit.sourceforge.net/doc/cookbook/cookbook.htm

        HTH

         

Log in to post a comment.