Testing classes without a main()...

i was wondering if its possible to run a test ona class without a main...my prof isnt letting us use "static" methods because it obviously defeats the purpose of OOD. So now im left wondering how the hell to get my test classes running...here is an example of one..i made the "main" method here static and it worked fine...but now how do i go about making it work non static?
import java.util.*;
import java.io.*;
public class BankAccountTest
public void main(String[] args)
     String testName = "Testy McTesterson";
     BankAccount test = new BankAccount();
     test.setBalance(100.00);
     System.out.println(test.getBalance());
     test.setName(testName);
     System.out.println(test.getName());
thanks in advance,
Cuda
Edited by: 74Cuda on Mar 8, 2008 7:28 PM

How the Java virtual machine "gets started" is covered in the JVM specification 5.2 "The Java virtual machine starts up by creating an initial class, which is specified in an implementation-dependent manner, using the bootstrap class loader (�5.3.1). The Java virtual machine then links the initial class, initializes it, and invokes its public class method void main(String[])". Note that it's a class - ie static - method that kicks the whole thing off. And it really has to be as no code has been run, and no objects created at this point.
http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html#51579
Magic involves suspending the everyday laws of nature and logic to effect the impossible. Stage magic merely hides these laws to create a pleasant illusion.
I suspect that IDEs' lack of an apparent static main() method when performing unit testing is just stage magic.
For instance junit.swingui.TestRunner includes this method:
public static void main(String[] args) {
    new TestRunner().start(args);
}

Similar Messages

  • Unable to run ADFBC JUNIT Test Classes with JDEV11G 11.1.1.6

    Dear All,
    I upgraded my project to the latest release JDEV 11G 11.1.1.6
    Previously we are on JDEV 11G 11.1.1.5
    I have a JUNIT class that I am running which test my ADFBC components.
    public class MyTestClass {
      @Test
      public void testVOAccess()
        //assertions
    }Unfortunately, I am hitting an error like this from the messages.
    Mar 9, 2012 1:28:07 PM oracle.adf.share.ADFContext getCurrent
    WARNING: Automatically initializing a DefaultContext for getCurrent.
    Caller should ensure that a DefaultContext is proper for this use.
    Memory leaks and/or unexpected behaviour may occur if the automatic initialization is performed improperly.
    This message may be avoided by performing initADFContext before using getCurrent().
    For more information please enable logging for oracle.adf.share.ADFContext at FINEST level.
    Mar 9, 2012 1:28:08 PM oracle.security.jps.internal.config.xml.XmlConfigurationFactory initDefaultConfiguration
    SEVERE: org.xml.sax.SAXParseException: Invalid encoding name "Cp1252".
    Mar 9, 2012 1:28:10 PM oracle.mds
    NOTIFICATION: PManager instance is created without multitenancy support as JVM flag "oracle.multitenant.enabled" is not set to enable multitenancy support.
    Mar 9, 2012 1:28:12 PM oracle.security.jps.internal.config.xml.XmlConfigurationFactory initDefaultConfiguration
    SEVERE: org.xml.sax.SAXParseException: Invalid encoding name "Cp1252".
    Mar 9, 2012 1:28:12 PM oracle.adf.share.jndi.ReferenceStoreHelper getReferencesMapEx
    WARNING: Incomplete connection reference object for connection:MYDATASOURCEAt the JUNIT Test Runner, I see this.
    java.lang.ExceptionInInitializerError: null
         java.lang.reflect.Constructor.newInstance(Constructor.java:513)
         org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:171)
         org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:216)
    Caused by: oracle.jbo.DMLException: JBO-26061: Error while opening JDBC connection.
         oracle.jbo.server.ConnectionPool.createConnection(ConnectionPool.java:207)
         oracle.jbo.server.ConnectionPool.instantiateResource(ConnectionPool.java:166)To validate the issue, I tried to run my same project using the older release which is JDEV 11G 11.1.1.5
    and I see that I am not hitting any error. All my test classes runs fine.
    Has anybody replicated this?
    Thanks

    Didier Laurent wrote:
    I logged the following bug for this issue:
    bug 14030895 - REGR: JDEVELOPER 11.1.1.6.0 JUNIT JBO-26061 ERROR WHILE OPENING JDBC CONNECTION
    Regards,
    Didier.So its really a bug..
    I abandon this already since I cannot find any solution to look up for this.
    On the other hand, I am maintaining two jdeveloper version just to get around this problem.
    When testing ADFBC, I used the 11.1.1.5 while for non-junit test I used the 11.1.1.6
    Hopefully this gets fixed on the next release as I am having a hard time swithcing between two JDev version.
    Thanks
    Edited by: Neliel on May 3, 2012 11:42 PM

  • How to reference a class without using the new keyword

    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();

    quedogf94 wrote:
    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();No.
    Using new does not erase anything. There's nothing to erase. It's brand new. It creates a new instance, and whatever that constructor puts in there, is there. If you then change the contents of that instance, and you want to see them, you have to have maintained a reference to it somewhere, and access that instance's state through that reference.
    As already stated, you seem to be confused between class and instance, at the very least.
    Run this. Study the output carefully. Make sure you understand why you see what you do. Then, if you're still confused, try to rephrase your question in a way that makes some sense based on what you've observed.
    (And not that accessing a class (static) member through a reference, like foo1.getNumFoos() is syntactically legal, but is bad form, since it looks like you're accessing an instance (non-static) member. I do it here just for demonstration purposes.)
    public class Foo {
      private static int numFoos; // class variable
      private int x; // instance varaible
      public Foo(int x) {
        this.x = x;
        numFoos++;
      // class method
      public static int getNumFoos() {
        return numFoos;
      // instance method 
      public int getX() {
        return x;
      public static void main (String[] args) {
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ();
        Foo foo1 = new Foo(42);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ();
        Foo foo2 = new Foo(666);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ("foo2.numFoos is " + foo2.getNumFoos ());
        System.out.println ("foo2.x is " + foo2.getX ());
        System.out.println ();
    }

  • Flash Builder 4.6 - How can I keep unit test classes out of the finished swc?

         I have a library of code I'm building and I'm working on unit testing but I have a major issue. When my finished swc compiles no matter what I do it includes the unit test classes as part of the intellisense if you load the swc via flash. The classes aren't really in the swc since if you just try and import them they'll come up undefined. They only appear to go into the intellisense for the swc. Does anyone know how can I keep this from happening in the finished source? Currently my folder setup is like this in flash builder.
    src\main - source documents for the library to get compiled
    src\mock - mock class area for unit testing
    src\test - unit test classes
         In the project Properties panel > the first tab of my Flex Library Build path I have selected only the src\main folder for the classes to inlude in the library. No other folder paths are selected.
    The "Flex Library Build Path" doesn't change my results with any setting.
    Thanks,

    Mel Riffe,
    Here's a Help topic about compiler options in Flash Builder: http://help.adobe.com/en_US/flashbuilder/using/WSe4e4b720da9dedb524b8220812e5611f28f-7fe7. html
    For information on using mxmlc, the application compiler, to compile SWF files from your ActionScript and MXML source files, you can see: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fcc.html
    Hope this helps,
    Mallika Yelandur
    Flash Builder Community Help & Learning
    Adobe Systems Incorporated

  • Problem in taking the control of my application in the test class

    Hi,
    I am calling an application(Login) from the test class. This test class tests for blank fields entered for the login application.
    Once i get the login screen, my program is getting hanged, i mean its not executing the test case unless i press the cancel button in that login screen. Only when i press the cancel button,my test case is executing in the background & is successful.
    Can anyone tell me why is this happening & is there a better way to handle this situation.
    Thanks & Regards,
    Vishal

    Well here is the Test class that i have written,
    * LoginScreenTest1
    * Created on Mar 9, 2007 by vishal
    package unittest.com.erp;
    import junit.extensions.TestSetup;
    import junit.extensions.jfcunit.*;
    import junit.extensions.jfcunit.finder.*;
    import junit.extensions.jfcunit.eventdata.*;
    import junit.framework.Test;
    import junit.framework.TestSuite;
    import junit.textui.TestRunner;
    import com.erp.client.swing.ClientLoginDialog;
    import com.erp.client.swing.workspace.ClientWorkspaceFrame;
    import com.erp.client.swing.workspace.data.LoginResults;
    import javax.swing.*;
    import junit.extensions.jfcunit.finder.Finder;
    import java.awt.Window;
    import java.awt.Robot;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.InputEvent;
    import java.util.List;
    import java.util.ArrayList;
    * MISSING_JAVADOC Vishal Class LoginScreenTest1 description.
    * @author Vishal
    public class LoginScreenTest1
        extends JFCTestCase {
      private  ClientLoginDialog loginScreen ;
      private static JFCTestHelper s_helper = null;
      private LoginResults lr;
      public LoginScreenTest1(String name) {
        super(name);
        s_helper = new JFCTestHelper();
        System.out.println("Calling Login dialog");
        loginScreen = ClientLoginDialog.login(new JFrame(),true);  // Returns the login dialog
        loginScreen.setVisible(true); // Its getting hanged here,only when i press the cancel button my test case gets executed
      public static Test suite() {
        System.out.println("I am in Suite");
        TestSuite suite = new TestSuite(LoginScreenTest1.class);
        return suite;
      public void testUserAndPasswordEmpty() {
        JDialog dialog;
        System.out.println("In Test case ");
        JTextField userNameField = (JTextField)s_helper.findNamedComponent("LoginTextField",loginScreen, 0);
        JTextField passwordField = (JTextField)s_helper.findNamedComponent("PasswordField",loginScreen, 0);
        JButton CancelButton = (JButton)s_helper.findNamedComponent("Cancelbutton",loginScreen, 0);
        userNameField.setText("");
        passwordField.setText("");
        JButton LoginButton = (JButton)s_helper.findNamedComponent("Loginbutton",loginScreen, 0);
        System.out.println("Clicking Login button");
        LoginButton.doClick();
        System.out.println("Login button clicked");
      public static final void main(String[] args)
        junit.textui.TestRunner.run(suite());
         try
            Thread.sleep(1000000);
         catch (Exception e)
    }Message was edited by:
    vishal_vj

  • Accessing class var from main timeline

    Hi all! Well I've been working on this for a couple of days
    now and just can't seem to get it to work right...... I'm still
    getting my feet wet with as3 and like it more and more everytime I
    use it.... almost.
    Anyways, here's where I'm running into trouble.
    Here's a dumbed down version of my project with all the other
    usless drivel excluded. Basically what I'm trying to do is declare
    a var and give it a value in my class. Then I want to be able to
    display that value on the stage and use it in the main timeline.
    Seems simple enough....
    I need to be able to pass the var from the class to the main
    timeline for use.... Any help on this would be GREATLY appreciated.
    Thanks.

    kglad, worked like a charm in my short test file... however
    in my real world flash file the class takes a short time to
    actually compute the value of the variable. If I fire the trace
    from the main timeline it will display NaN b/c at the moment it
    fires the value of the var doesn't exist b/c it has yet to be
    calculated......
    I don't really know the best way to delay this... would the
    best way be to somehow add an event listener to listen to the var
    to see when it is assigned a value?.... I'm open to suggestions.
    btw, good catch on the assignment of a string value!!
    Thanks!

  • Import class without package

    hellow, i have a web aplication named test , and i have a class named conexion
    when i import a package "pack" with the class conexion, not problem (test/WEB-INF/classes/pack/conexion.class) <% import="pack.* " %> but when i have only the class conexion WITHOUT package (test/WEB-INF/classes/conexion.class) and i import <%import ="conexion" %> i have problem ("The import conexion cannot be resolved") and when i not import the class i have problem (conexion cannot be resolved to a type) , my question is:
    how to i import a class without package in JSP , and if the test/WEB-INF/classes is in the classpath when compile the servlet , why the tomcat not found the class conexion?
    (tomcat 5.5.20 , jdk 1.5.09 , vim)
    thank
    (Sorry my english , i'm from Chile)

    Hi I am hosting my JSP application with Resin 2.17 which uses classes directly in JSP code (not packages). To make this work I had to specify the classpath in Resin.conf and it worked.
    My problem is getting this to work with TomCat or any other application server that will allow me to debug my project in Eclipse or NetBeans IDE. (I have yet to find an IDE that Supports debugging JSP/Java code running on Resin - so I want to switch my application server but I am not sure how to configure my classpath for the application servers to look for java classes in the specified directory just like I did with Resin.

  • How to make a Abap Unit Test Suit with many test classes

    Hi,
    Problem space
    we have different packages(embedded) in our project and each package corresponds to a differnt functional layer in the design.
    We want to create abab unit test classes for these different layers.
    say embedded package 1 has 10 unit test classses
          embedded package 1 has 20 unit test classses
    How to grup these classes together so that we can start them frm a test suite.
    Code examples and blogs links will be appreciated.
    regards
    anubhav

    This sounds a bit like Project Administration 101 to me.
    I'm not exactly sure what you are actually trying to do here --but generally if you want to functionally test something you need to start with a business process -
    You need to create scripts which tell the user the data to be entered, the transaction to be used and the outcome.
    With SAP you might need to show screen shots of each stage as well.
    You follow this for each complete business process until you've covered the whole business cycle.
    You complete this say individually for Logistics, Purchasing and Finance and then compare what SAP gives you with what you expected to get.
    For some type of testing CATTS can help but without the business processes any testing is essentially meaningless.
    It is totally pointless trying to design a "generic" test plan until you've got the functional consultants to describe the business processes involved.
    Cheers
    jimbo

  • Can anyone help me with this test class

    hiya im new to java im trying to make this test class but i comes up with this error
    EmployeeTestClass.java:14: cannot resolve symbol
    symbol  : constructor Employee  (java.lang.String,java.lang.String,java.lang.String)
    location: class Employee
         Employee Test = new Employee ("John", "Henry", "Monthly");
                                ^here is my whole code to the test class, please bear in mind im really new to java
    public class EmployeeTestClass
       public static void main(String[] args)
         System.out.println ("Please type the employee name:");
              String fName = EasyIn.getString();
         System.out.println ("Please type the employee secound name :");
              String sName = EasyIn.getString();
         System.out.println ("Please type the employee eReference :");
              String  eReference = EasyIn.getString();
         System.out.println ("Please type the employee annualSalary :");
              String  annualSalary = EasyIn.getString();      
         Employee Test = new Employee ("John", "Henry", "Monthly");
       Test.showDetails();
    }

    // your code:
    Employee Test = new Employee ("John", "Henry",
    "Monthly");What you need to do is put the
    variables fName, sName etc. in there instead. And you
    declared the variable annualSalary as a
    String, which should be a double.hiya i tried the above and now my code code like this
    public class EmployeeTestClass
       public static void main(String[] args)
         System.out.println ("Please type the employee name:");
              String fName = EasyIn.getString();
         System.out.println ("Please type the employee secound name :");
              String sName = EasyIn.getString();
         System.out.println ("Please type the employee eReference :");
              String  eReference = EasyIn.getString();
    System.out.println ("Please type the employee salary :");
              double  annualSalary = EasyIn.getString();
    Employee Test = new Employee ("fName", "sName", "annualSalary");
       Test.showDetails();
          }but wheni try to complie it it comes up with these error please help
    EmployeeTestClass.java:12: incompatible types
    found   : java.lang.String
    required: double
    double  annualSalary = EasyIn.getString();
                                                              ^
    EmployeeTestClass.java:15: cannot resolve symbol
    symbol  : constructor Employee  (java.lang.String,java.lang.String,java.lang.String)
    location: class Employee
    Employee Test = new Employee ("fName", "sName", "annualSalary");
                         ^
    2 errors

  • ?Is it possible to create a javafx class without extending Application class ? If yes, how

    Is it possible to create a javafx class without extending Application class ? If yes, how ?

      There is no  such thing as a javafx  class.  It is a regular  java class.  The Aapplication class is  the entry
    point  for JavaFX application.  You have to extend the Application class to create Javafx  application .

  • Error in Smartforms a page without a main window

    Dear Friends
    I have suffred one problam in Smartforms, whe we create new page then system gives error
    "A page without a main window cannot point to itself as next page".
    Please provide solution.
    Regards
    Ajit Sharma

    Hello Ajit,
    In Smart Form Main window is optional but check if this satisfies in your case ....
    Main Window
    In a main window you display text and data, which can cover several pages (flow text). As soon
    as a main window is completely filled with text and data, the system continues displaying the text
    in the main window of the next page. It automatically triggers the page break.
    You can define only one window in a form as main window.
    The main window must have the same width on each page, but can differ in height.
    A page without main window must not call itself as next page, since this would trigger
    an endless loop. In such a case, the system automatically terminates after three
    pages.
    It means if you have Next page you need to use a Main window in your smart form.
    Regards,
    Kittu

  • Generating a test result without a module

    I have a basic question about generating a test result without calling a module in TestStand.
    For example, I do a pair of read operations from a product and return the results to a pair of numeric local variables. Now I want to do a sequence pass/fail or numeric limit test based on these two values. The results are already available and I can do a function step to test a result, say from a basic math operation. But I can't create a pass/fail result from a function step. I've gotten around the issue by creating a dummy module that has no function other than to allow me use the expression builder to assign a result to one of the step result items, but this sure seems stupid.
    What am I missing?
    Thanks,
    Dave
    Solved!
    Go to Solution.

    Do it in the Pre-expression.
    Use the <none> adapter as suggested and place down a Numeric Limit Test step.  Then in the Pre-Expression put something like this:
    Step.Result.Numeric = Locals.A - Locals.B
    If you look at the Data Source tab you will see the variable which gets evaluated and compared against the limits.
    In fact if you wanted to you could avoid the Pre-Expression and just put your calculation in the Data Source Expression:
    Locals.A - Locals.B
    You can set up the Limits on the Limits tab for that step.
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • Classes without packages not accepted by ejbc compilation ?

    Hey guys ...
    I noticed something which I found unusual...I mite be missing something out here
    When ejbc generates the Bean IMPL class , it does not put any import statements
    in the generated java file but references all the classes in the Bean with their
    absolute path ...
    Now ..I have a 3rd-party jar which does not have certain classes in packages...and
    I reference these classes within my Session Bean...the session bean compiles properly
    ..but when ejbc happens and the Impl class gets generated with the absolute path
    and no imports...the compiler expects to find all these 3rd-party classes without
    packages within the current session bean package itself which it will not..and
    hence throws all sorts of "cannot resolve symbol" errors...
    Does this mean that within my EJB beans I can never reference classes without
    packages or is there something I am missing..?
    Thanx,
    Krish

    Rob ,
    I agree with u that giving classes without package is not a good practise..but
    Itz got a history which believe it or not stems from another weblogic problem(related
    to webservices..)
    anywayz..that is another issue alltogether...
    I don't think this bug is fixed...coz I checked a WLS70 Impl and it is still generating
    the IMPL without the imports...
    But can u clarify..what u wud mean by "fixing the bug" ..does it mean that the
    Impl would start putting the imports..?
    Thanx,
    Krish
    Rob Woollen <[email protected]> wrote:
    I recall this bug being reported before. You might try the latest
    service pack and see if it's been fixed already. Otherwise, you'll have
    to contact [email protected]
    FWIW, it's quite disturbing that a 3rd party would give you a jar
    without a package.
    -- Rob
    Krishnan Venkataraman wrote:
    Hey guys ...
    I noticed something which I found unusual...I mite be missing
    something out here
    When ejbc generates the Bean IMPL class , it does not put any import
    statements
    in the generated java file but references all the classes in the Bean
    with their
    absolute path ...
    Now ..I have a 3rd-party jar which does not have certain classes in
    packages...and
    I reference these classes within my Session Bean...the session bean
    compiles properly
    ..but when ejbc happens and the Impl class gets generated with the
    absolute path
    and no imports...the compiler expects to find all these 3rd-party
    classes without
    packages within the current session bean package itself which it will
    not..and
    hence throws all sorts of "cannot resolve symbol" errors...
    Does this mean that within my EJB beans I can never reference classes
    without
    packages or is there something I am missing..?
    Thanx,
    Krish

  • Transport of ABAP Unit Test Classes between systems.

    Hi guys
    I have a bit of a dilemma on hands here pertaining to the transport of ABAP Unit test classes. Generally when you create a transport containing classes the transport manager will automatically include all "programs" related to the class like the local type definitions, local implementations and with ABAP Unit the local test classes.
    <b>The question that I have is how would one go about excluding the ABAP Unit test classes in transports to production systems and pre-WAS 6.40 systems that do not support ABAP Unit? Does the transport system automatically manage this for you?</b> Any help ideas regarding this would be greatly appreciated.
    Kind regards
    Ettienne Hugo

    Hello Ettienne
    I have a very similar problem that I have to maintain objects for release 6.20 and 6.40. Since I appreciate ABAP Unit Tests as being very helpful I do not want to miss them even in such a situation.
    My approach is as following:
    - If possible, I try to separate the local classes from the tested object, for example:
    - Report or function group
         - contains an include like <z_include_ft01>
                - Within <i><z_include_ft01></i> I have a single stament <i><z_include_au01></i>
    The actual ABAP Unit Tests are coded in <z_include_au01>. Now if I need to ship the development to a release < 6.40 the only thing I need to do is to comment the single INCLUDE statement in <z_include_ft01>. This manual step cannot be ommitted (however, it would be simple task to define an eCATT doing this). In addition, include <z_include_au01> should not be in the transport request for the development (if it happened the import error would not affect the function of the development because it is no longer linked together).
    Advantage of this approach:
    - I clearly see that my development contains ABAP Unit Tests (use naming conventions for the includes) and
    - I can ship - with little effort - the development to SAP releases not supporting ABAP Unit Testing yet
    Regards
      Uwe

  • How do you call a java class from the main method in another class?

    Hi all,
    How do you call a java class from the main() method in another class? Assuming the two class are in the same package.
    Thanks
    SI
    Edited by: okun on May 16, 2010 8:40 PM
    Edited by: okun on May 16, 2010 8:41 PM
    Edited by: okun on May 16, 2010 8:47 PM

    georgemc wrote:
    To answer your impending question, either the method you're calling has to be static, or you need an instance of that other class to invoke it against. Prefer the latterAnd to your impending question after that: no, don't use the Singleton pattern.

Maybe you are looking for