Jtest FAQs - Gheorghe Asachi Technical University of...

41
Jtest FAQs 1 Jtest FAQs General Customizing Test Parameters Static Analysis White-Box Testing Black-Box Testing Coverage Projects Troubleshooting Error Messages Problems UNIX General What operating systems does Jtest currently support? Windows 95/98/NT/2000, Solaris 2.7, and Linux. What are the system requirements for Jtest? Windows: Windows NT/2000 or 98/Me Pentium compatible 300MHz or higher (400 recommended) 128 MB of RAM Linux: 400MHz Pentium compatible 128 MB of RAM

Transcript of Jtest FAQs - Gheorghe Asachi Technical University of...

  • Jtest FAQs

    Jtest FAQsGeneral

    Customizing Test Parameters

    Static Analysis

    White-Box Testing

    Black-Box Testing

    Coverage

    Projects

    Troubleshooting

    Error Messages

    Problems

    UNIX

    GeneralWhat operating systems does Jtest currently support?

    Windows 95/98/NT/2000, Solaris 2.7, and Linux.

    What are the system requirements for Jtest?

    Windows:

    • Windows NT/2000 or 98/Me

    • Pentium compatible 300MHz or higher (400 recommended)

    • 128 MB of RAM

    Linux:

    • 400MHz Pentium compatible

    • 128 MB of RAM

    1

  • Jtest FAQs

    • Supports RedHat Linux 6.1 or 6.2

    • Gnome or KDE Windows Managers

    • Kernel: 2.2.12-20 or 2.2.14-5

    • libc: libc-2.1.2 or 2.1.3

    Solaris

    • Solaris 2.7

    • 256 MB of RAM

    • 333MHz processor

    Can Jtest single step through the code like a debugger?

    No.

    Can Jtest test GUI applications?

    Jtest doesn't test at the application level. It tests at the class level. Youcannot simulate user defined actions such as button presses and menuselections with Jtest.

    Does Jtest have its own virtual machine?

    Yes, it implements its own virtual machine.

    When I start up Jtest, why do I keep getting “font not found”messages?

    This is a known bug in Java. Please see the Java Developer Connectionfor a description of the bug (number 4276129).

    2

  • Jtest FAQs

    Does Jtest test the classes from the import statements in my class?

    No. You might think that Jtest is testing the classes called in your importstatements in the source file, but Jtest only tests the classes that you tell itto test. Jtest simply calls those methods it needs to test the specifiedclass.

    How does Jtest handle threads? Does it detect thread-related prob-lems?

    It does not test threads nor does it detect thread-related problems.

    Do I have to modify JUnit test classes in order to use them withJtest?

    No. You can use your JUnit test classes in Jtest without modifying them.

    Can Jtest test applications compiled with JDK 1.3?

    Jtest 4.0 supports JDK 1.3.

    What if I already have the JDK installed on my machine and I want tochange the JRE that Jtest uses to another version of the JRE orJDK?

    It is not possible to use a different JRE to run the Jtest user interface. Theuser interface was designed to run with the JRE that is included withJtest.

    3

  • Jtest FAQs

    For the automatically generated test cases, can I subclass them tomy own test cases?

    You cannot subclass the Jtest generated test cases. They are stored andmanaged internally by Jtest. If you would like to add your own test cases,consider using Jtest's Test Classes.

    When I run the jtest-install script on my UNIX platform, a lot of“permission denied” messages appear. How can I fix these andinstall the product?

    This means that you do not have write permissions in the directory whereyou are attempting to install Jtest. Either grant write permission for thatdirectory to yourself, or install Jtest as the user that has write permissionin this directory.

    How is regression testing handled with respect to GUIs?

    Regression testing checks that the class behavior doesn't change afterthe class has been modified. Jtest remembers the outcomes from previ-ous test runs, compares outcomes every time the class is tested, andreports an error for any outcome that changes.

    Jtest does not test GUIs or keep track of any previous GUI selections.Jtest tests classes.

    I found a manual way of telling Jtest to ignore all non-user definedtest cases. However, is there a simpler way of doing this (eitherthrough a batch process command parameter, or a global setting forthe Project UI)?

    This cannot be done at the command line level at this time. For now, youcan define multiple project test parameters and use the different .ptpfiles at your convenience.

    4

  • Jtest FAQs

    How do I test applets and servlets?

    Jtest is not an applet testing tool. However, you can test the applet'sclasses and the methods of the classes using Jtest.

    The best way to do this is by using Test Classes (see the User Guide).Write test cases in the Test Class. Each test case can call and test themethods of the applet to test the calls to the getResource method.

    At this time, Jtest can’t test specific security restrictions inapplets/servlets. Jtest tests each class individually; so when testing agiven class it is unable to tell if the class is going to be used in an appletor in an application.

    How do I automate testing to the point that I can have the IDE issue abatch command when it compiles that runs a series of regressiontests? What kind of performance can I expect?

    Define your project and send these project test parameters (the .ptp file)to the jtestgui command using the -test flag. Performance gains will benegligible because most of the cpu time is spent in the Jtest virtualmachine (not the UI), when performing tests.

    For more information on the batch command, see the User Guide or typejtestgui -help from the command line.

    Is it possible to generate a report when running Jtest from the com-mand line?

    Yes. To do so, perform the following steps:

    1. Start Jtest.

    2. In the Project Testing UI, define the parameters for the projectand save the parameters by using File> Save As .

    5

  • Jtest FAQs

    3. Run the project from the command line using the -report flag,for example:

    jtestgui -summary_report summary.rpt -ptp

    c:\progra~1\parasoft\jtest\tests\MyTest.ptp

    This will run the previously tested MyTest test whose test parameters aresaved in c:\progra~1\parasoft\jtest\tests\MyTest.ptp , thengenerate a summary report (summary.rpt) in the current working directory

    Please see jtestgui -help for more report options.

    How do I add an input value to the THIS argument for my instancemethod?

    In general, it is best to use Test Classes to perform black-box testing. Forinformation on using Test Classes, see the Jtest User’s Guide. If youprefer to use the older method of adding test cases, perform the followingsteps:

    1. Get the name of the type of the THIS argument. (The type will bethe same name as the class under test.)

    2. Open the class under test’s Class Test Parameters.

    3. Right-click the Dynamic Analysis> Test Case Generation>Automatic> Restricted Inputs> “THIS” object.

    4. Choose Set Restricted Input from the shortcut menu.

    5. In the text box that appears below the THIS argument, enter theJava expression that will be used to instantiate the class.

    For example: If the class name is com.mediaconnex, and theclass had a default constructor, enter new com.mediacon-nex()

    Also, if the class needs more than just one line to be instantiated, defineand use an Inputs class instead. An error will occur if you either don’t usethe full class name to instantiate the class, or leave out the input for theTHIS argument.

    6

  • Jtest FAQs

    How do I change the editor Jtest uses to display the source file?

    Perform the following steps:

    1. In either Jtest UI, choose Preferences> ConfigurationOptions> Editor .

    2. Change the setting to the editor of your choice.

    How do I turn off all tip dialogs in Jtest?

    In either Jtest UI, choose Preferences> Configuration Options> Tips>Deactivate All .

    How do I generate a report in HTML format?

    In either Jtest UI, choose Preferences> Configuration Options> ReportFormat> HTML .

    How do I view test results after my license has expired?

    To view test results after your license has expired, go to

    {installation_dir}\u\{username}\persist\history

    and look for a large .rep file. The .rep files are the summary reports forall the Project tests run.

    This method can also be used when the Jtest UI crashes while you wereusing new.ptp (i.e. you didn't save the Project Test Parameters into a.ptp file). Results from running under new.ptp are lost whenever theJtest UI restarts, the only things left are the .rep and .log files in thehistory directory.

    7

  • Jtest FAQs

    How do I set the source path for Jtest?

    Perform the following steps:

    1. From either the Project Test Parameters window, Class TestParameters window, or the Global Test Parameters window, openthe Common Parameters branch.

    2. Under the java/javac-like Parameters branch right-click on thesource path node and choose Edit .

    3. In the source path window, choose Browse , and browse to theroot directory of the java source file of interest.

    For example: if you need to point Jtest to apples.java in the fruitsdirectory, add to the path "...\fruits".

    4. After opening the selected root directory, click Add to add it to thesource path list.

    You will have to add a root directory to all java source filesneeded in the project, one at a time.

    5. When done, save and close the source path window by clickingOK.

    Note: Jtest will not allow a zip file of any kind to be added to the sourcepath. If you choose to browse to the actual java file when Jtest promptsyou for the requested java source file, Jtest will add the path to the rootdirectory of the java source file automatically.

    How do I test database connectivity?

    Jtest is a unit testing tool; it is not meant to test application level opera-tions such as database connectivity. For classes using external resources(such as connecting to a database) Jtest provides automatic stubs for thedatabase connection.

    How do I view test cases in the report file for a class?

    8

  • Jtest FAQs

    In either UI, choose Preferences> Configuration Options> Report File ,then check Show Test Cases .

    Is a 256 color graphics card a requirement for jtest?

    No. However, without a video card that supports 256 colors, some por-tions of the UI might not appear as they should.

    How do I save a report to a specified directory before testing aproject or a class in Jtest?

    Perform the following steps:

    1. Open the Project/Class Test Parameters window.

    2. Open the branches Common Parameters> Directories .

    3. Right-click the Results option and choose Edit .

    4. In the text dialog enter or browse to the specified directory.

    When I use Jtest's View Source feature, does Jtest disassemble thesource from the bytecodes, or does it use the actual source code?

    Jtest's View Source feature uses the actual source code.

    Does Jtest integrate with Rational Robot?

    No, currently Jtest is a standalone tool. Rational Robot is good for testingat the Application level, while Jtest is good for testing at the unit level.

    Where is the RuleWizard documentation located online?

    9

  • Jtest FAQs

    You can view the RuleWizard documentation online at:http://www.parasoft.com/products/jtest/manuals/v4_0/rulewiz-ard/index.htm

    Is it mandatory to provide .java files when doing dynamic analy-sis?

    No, it is not mandatory to provide .java files for dynamic analysis,unless you want to view the source code at the line where the exceptionoccurred. It is necessary to provide .java if you want to perform StaticAnalysis.

    What is the difference between white-box testing and black-box test-ing?

    White-box testing checks that a class is structurally sound. It does not testthat a class behaves according to specification. Instead, it ensures that aclass does not crash and that it behaves correctly when passed unex-pected input.

    Black-box testing checks that a class behaves according to specification(test cases the user generates). It checks that the class produces the cor-rect output (outcomes) for each input. Inputs are generally derived not byexamining the code's structure (as they are in white-box testing), but bylooking at the specification that defines what the code is intended to do.

    Customizing Test ParametersHow do I determine what types of methods Jtest tests?

    Perform the following steps:

    1. In either Jtest UI, open the Global Test Parameters by clickingGlobal ,

    10

  • Jtest FAQs

    2. Open the branches Dynamic Analysis> Test Case Generation>Automatic> Test Methods .

    3. Enable/disable the options available in this branch so that theyrepresent the types of methods you want Jtest to test.

    How do I tell Jtest where to find files it can’t automatically locate?

    You can indicate the location of this class by modifying the CLASSPATHenvironment variable on your system so that it points to the directory con-taining the class that was not found by Jtest.

    You can also use enter CLASSPATH information in the Global TestParameters tree. Click the Global button, then indicate the classpath inCommon Parameters> java/javac like parameters> by double-clicking-cp (if you want to prepend CLASSPATH) or Common Parameters>java/javac like parameters> by double-clicking -classpath (if you wantto override CLASSPATH).

    How do I indicate the location of my source?

    Perform the following steps:

    1. Click Global to open the Global Test Parameters window.

    2. In the Global Test Parameters window, click the CommonParameters node, then double-click the Source Path node. Adialog box appears.

    3. In the dialog box, enter (or browse to) the directory location ofyour source code. If the source code is contained in a packagehierarchy, specify the root of the hierarchy (e.g., the directorycontaining “COM”).

    4. Click Add to permanently add this information.

    How do I suppress the reporting of all NullPointerExceptions?

    11

  • Jtest FAQs

    Perform the following steps:

    1. Click Global to open the Global Test Parameters.

    2. Go to Dynamic Analysis and double-click Suppressions Table .The Suppressions table will open.

    3. In the Suppressions Table, right-click any area, then choose AddNew Suppression from the shortcut menu that opens. Four textfields will appear.

    4. In the Class field, enter *

    5. In the Method field, enter *

    6. In the Exception field, enter java.lang.NullPointerEx-ception

    How do I refresh Class Test Parameters to include recently addedmethods?

    Perform the following steps:

    1. Load your class and modify any parameters that you want tochange.

    2. Choose File> Save to save your class test parameters.

    3. Modify and compile your class.

    4. Reload your Class Test Parameters by choosing File> Open .

    How do I open a previously saved Class Test Parameters file orProject Test Parameters file?

    Perform the following steps:

    1. From the UI (appropriate to the type of file you want to open),choose File> Open .

    2. Browse to your .ctp file (if opening a Class Test Parameters file),or your .ptp file (if opening a Project Test Parameters).

    12

  • Jtest FAQs

    In the Class Test Parameters window, under the Dynamic Analysis>Test Case Generation> Automatic> Restricted Inputs branch, thereis a THIS object parameter. What does the THIS object mean or whatis it used for?

    When Jtest tests classes, it instantiates the class and uses that instanceto test the class's instance methods. It instantiates the class by calling themost general constructor (the one with the most arguments). You canspecify which instance of the class Jtest should use by using theRestricted Inputs to choose the THIS object.

    Static AnalysisCan Jtest locate .java files in a jar file?

    No, the .java files need to be extracted from the jar file into a directory.Jtest can only locate .java files or source code that is in a directory. Ifyou try to add a jar file to the source path, you will get an error.

    Can I change the severity levels of Jtest’s built in static analysisrules?

    No.

    How do I skip static analysis if the source is not found?

    To have Jtest skip the static analysis test for a class that doesn't have the.java file, perform the following steps:

    1. In the Project Testing UI, open the Project Test Parameters win-dow by clicking the Project button.

    13

  • Jtest FAQs

    2. Open the Search Parameters > Static Analysis branch.

    3. Enable the Skip if .java file not found option.

    How do I view the static analysis rule descriptions?

    Perform the following steps:

    1. In either Jtest UI, open the Global Test Parameters window byclicking the Global button.

    2. Open the Static Analysis> Rules> Built-in Rules branch.

    3. Open the branch (Naming Conventions, Coding Standards, etc.)that has the rule.

    4. Right-click on the rule violation line and choose View RuleDescription . A dialog window appears containing a descriptionof the rule.

    Note: If the rule doesn't apply to your coding standards, disable the ruleby right-clicking on an error message related to this rule and selectingSuppress , or disable the rule in the Global Test Parameters window byclicking the diamond box in front of the rule.

    What Jtest static analysis rules are from Scott Ambler's “Elementsof Java Style”?

    The following Jtest static analysis rules are from Scott Ambler's “Elementsof Java Style.”

    • Naming Conventions: All. You can customize these rules by edit-ing the regular expressions that they use.

    • Javadoc Comments: All.

    • Class Metrics: Number of lines in class and method (CTNL,TNLM). Set the threshold to low. Define small classes and smallmethods.

    14

  • Jtest FAQs

    • Object Oriented Programming: OOP.APPF and OOP.APROFmake all fields private.

    • Possible Bugs: PB.UEI (use equals (), not ==).

    • Miscellaneous: MISC.CTOR (Do not call nonfinal methods fromwithin a constructor).

    • Optimization: OPT.CS (Use a finally block to release resources).

    • Threads & Synchronization: TRS.NSM (Avoid synchronization).

    White-Box TestingHow do I stop Jtest from reporting uncaught runtime exceptions?

    Perform the following steps:

    1. In either Jtest UI, click Global .

    2. Open the branches Dynamic Analysis> Test Case Evaluation .

    3. Disable the Report Uncaught Runtime Exceptions option.

    How do I stop Jtest from automatically generating test cases?

    Perform the following steps:

    1. In either Jtest UI, click Global .

    2. Open the branches Dynamic Analysis> Tests Case Execution .

    3. Disable the Execute Automatic option.

    How do I find out why suppressed exceptions were suppressed?

    Perform the following steps:

    1. Open the View Test Cases window.

    2. Locate the exception you want to find out about.

    15

  • Jtest FAQs

    3. Right-click the exception message for that exception (this is thenode that begins Exception: ). A shortcut menu will open.

    4. Choose Why Suppressed? from the shortcut menu. A dialogbox will open; this box will display the reason why the selectedexception was suppressed.

    How does Jtest generate complex object type inputs to the methodof a class?

    To create a complex object type, Jtest calls the most general constructorof the object (the constructor with the most arguments).

    How does Jtest handle native code (C/C++) in classes?

    If Jtest finds a native method definition is part of a class definition, it willnot call that method. However, if Jtest finds a native method call when ittests a non-native, it will attempt to call that native method. It does not seeinto the native method; no coverage information is reported on the call tonative methods because it only reports coverage information on the byte-codes of the classes it tests.

    Can Jtest test my Enterprise Java Beans (EJB)?

    Yes. It uses automatically generated stubs to simulate interaction with anyexternal resources such as the container context or other servicesneeded by the EJB.

    If you notice that you are getting low coverage, then the data that is beinggenerated is not sufficient enough to cover most statements in the bean.In this case, it is necessary to write user defined test cases that test thebusiness methods of the beans. The test cases might include user-defined stubs that simulate interaction with any external resource.

    16

  • Jtest FAQs

    Can Jtest help me to test true database connectivity of my EJBs orother Java class files?

    No. Jtest is not designed to test the database connectivity of EJBs or truedatabase communication.

    How do I test my classes that interact with JDBC, RMI, or an Applica-tion Server?

    The difference between these classes and classes that do not use theseAPIs is that these classes make calls to resources external to the testedclass and/or the class's package. However, they are tested the same asany other class; simply load the class into the Class Testing UI and clickthe Start button.

    With Jtest, you can expect to see lower than normal coverage for theseclasses that make calls to external resources. To increase coverage,please use Test Classes to define test cases that test the methods ofthese types of classes.

    For Test Class information, please see the tutorial on Test Classes.

    What is the difference between direct NullPointerExceptions andregular/indirect NullPointerExceptions?

    Direct NullPointerExceptions are the exceptions that occur when a nullvalue is passed to a method. Subsequently, this method attempts to usethis null reference in a context where an actual object reference isrequired.

    Indirect NullPointerException's encompass all the other nullpointer excep-tions that are thrown. These exceptions are a result of objects (containedwithin the method) being dereferenced that were not properly initializedby constructors or setter methods.

    A direct NullPointerException will be thrown if 'null ' is used as input tothe method below:

    17

  • Jtest FAQs

    ...method ( Object o ) {

    ...o.doSomething();...

    }

    An indirect NullPointerException will be thrown for the call'c._o.doSomething ' below if the Ctor object used as a parameter isnot properly initialized. For example:

    private Object _o = null;...Ctor ( Object o ) {

    ..._o = o;...

    }

    method ( Ctor c ) {...c._o.doSomething();

    }...

    In Jtest, direct nullpointer exceptions are suppressed by default. Othernullpointer exceptions are reported in the Errors Found Panel of the ClassTesting UI), or under the Errors Found branch in the Project Testing UIResults Panel.

    18

  • Jtest FAQs

    Black-Box TestingIn general, it is best to use Test Classes to add user-defined black-boxtest cases. Test Classes are more expressive and robust than test casesmanually-entered through the Jtest UI. If you would like to use the newmethod, see the section in the User Guide related to Test Classes. Mostproblems and questions regarding the set up of test cases through theJtest UI can be solved with Test Classes.

    How do I determine what file a method under test opens?

    See the Black-Box Testing Tutorial.

    How do I set expected results when member functions return com-plicated objects such as hashtable or vectors?

    Use the jtestInspector method to set the results. The jtestInspector is amethod provided by the end-user that is included with the class definitionof the outcome class. You can use this jtestInspector method to constructa java.lang.String representing the state of the complicated object.For more information on using the jtestInspector method, see theBlack-Box Testing Tutorial.

    Can I import my own test cases?

    Yes. See “Using Test Classes” in the black-box testing section of the JtestUser’s Guide.

    Is there a way to import my own test data to the input methods,instead of entering them manually?

    Yes, by creating Test Classes.

    19

    products/jtest/manuals/v3_3/tutorials/html/less3.htmproducts/jtest/manuals/v3_3/tutorials/html/less3.htm

  • Jtest FAQs

    Currently, when I use jtest.TestClass.main(new String [] {"MyClassTest" }); in main , all of the tests but stubs are executed.Is there a way to force Jtest to use the stubs methods when runningthe test outside either the Class or Project UI?

    No. It is necessary to use the Jtest UI for Test Classes to call the stubsmethods.

    How do you save test cases per class base?

    When you save your project (.ptp ) in the Project Testing UI window youare also saving all the test cases you generated for each class. In otherwords, it saves the Class Test Parameter (.ctp ) setting for each class.

    How do I specify the order in which methods are called for black-boxtesting?

    Jtest tests one method at a time. To have Jtest test an object that hasbeen set up in a certain state (i.e. its instance methods have been calledbeforehand), first use the Inputs Repository to define a method that setsup an object in a certain state and returns it. Then, the method is used toreturn an object that is used for the implicit THIS object.

    For example, if you wanted to call fillRandom(), then sortAscending(),then print(), you would define the following method:

    Decl:MyObject setState ()

    Body:MyObject retVal = new MyObject ();retVal.fillRandom ();retVal.sortAscending ();return retVal;

    Then set the input for the implicit THIS object for the final method, print ();this is accomplished through the print() node in the Class Test Parame-ters (in the Class Testing UI, click the Class button). Use the Add Input

    20

  • Jtest FAQs

    From Repository option to set the THIS object. See the Black-Box Test-ing Tutorial for an in-depth technical description of how to specify THIS foran argument.

    How do I indicate which instance I want Jtest to use when it instanti-ates a class?

    When Jtest tests classes, it instantiates the class and uses that instanceto test the class’s methods. It instantiates the class by calling the mostcommon constructor. You can tell Jtest what instance of the class to useby restricting inputs using the THIS object. For more information on usingthe THIS object, see the Black-Box Testing Tutorial.

    How do I test a specific calling sequence?

    Please see the tutorial on Test Classes. With Test Classes you can test acalling sequence and check the state of the object using asserts. Also,you can write complicated test cases that depend upon a specific callingsequence.

    For example:

    class MyTest extends jtest.TestClass {

    public static void testSequence () {MyObjec t m = new MyObject (0);// ensure the total after the following

    sequence is '5'm.add (10);m.divide (2);m.add (2);m.sub (2);

    assert ("total is not 5", m.getTotal () == 5);}

    }

    21

    products/jtest/manuals/v3_3/tutorials/html/less3.htmproducts/jtest/manuals/v3_3/tutorials/html/less3.htmproducts/jtest/manuals/v3_3/tutorials/html/less3.htm

  • Jtest FAQs

    How do I test methods that depend on inputs of user-defined types?

    See the Tutorial on Test Classes.

    How do I add vector inputs?

    See the Tutorial on Test Classes.

    How does Jtest test a class with members that have user definedclass objects for arguments, including the constructors of thoseclass objects that use other class objects as arguments?

    Jtest instantiates the class using its constructor. If the constructor takes auser-defined class as a parameter, Jtest has to instantiate that class aswell as using its constructor. Once Jtest has instantiated the class, theclass can then be used for input when executing the class’s members.

    See \examples\dynamic\white-box\Constructor.java for ways to have Jtest select certain construc-tors.

    Is it possible to add a user defined label to individual test cases thatcan be output as part of the report?

    Yes. For the user defined test cases in the Test Classes, the test methodnames are the labels and the String literals in the assert statements arethe labels of the assertions. There are no labels for automatically gener-ated test cases. To be able to see the test cases in the report file, see"How do I view test cases in the report file for a class?"

    22

  • Jtest FAQs

    How can I run the Test Class I wrote using the standard Java inter-preter outside of the Jtest environment?

    There are two options:

    1. Use the following command:

    java jtest.TestClass

    This will run your Test Class with the Java interpreter and print a summaryof the test.

    Note: You need to have the jtest.zip file in your CLASSPATH to executethis command.

    2. Add to your Test Class a main method:

    public static void main (String args[]) {jtest.TestClass.main (new String [] {""});}

    This will run your Test Class with the Java interpreter and print a summaryof the test.

    Note: You need to have the jtest.zip file in your CLASSPATH to executethis command.

    How do I load a class into the Class Testing UI from the Project Test-ing UI?

    1. In the Results panel of the Project Testing UI, right-click on theclass name.

    2. From the shortcut menu, choose Load in Class Testing UI .

    How do I show all the test cases for each class tested at the projectlevel?

    23

  • Jtest FAQs

    Test cases aren't shown at the project level. They are only shown for indi-vidual classes. To see automatically generated test cases for each classfrom the Project Testing UI, load the class into the Class Testing UI, thenpress the View button.

    How do I test getter and setter methods?

    Please see the tutorial on Test Classes. You can write a test case usingTest Classes that can both check the state of an object after a settermethod is called, and that getter methods return the appropriate values.

    For example:

    public class MyTest extends jtest.TestClass {public static void testGetAndSet () {

    MyObjec t o = new MyObject ();o.setValue (100);

    assert ("getValue returned an incorrect value",o.getValue () == 100);

    }}

    Does Jtest work with IBM's VisualAge Java class repository or doesit require classes to be exported to directories?

    You must export your classes to directories before they can be tested withJtest.

    Why does Jtest report NullPointerExceptions for most of the meth-ods in the class?

    The reason for the NullPointerExceptions could be that a member vari-able used by the methods needs to be set. When testing a member

    24

  • Jtest FAQs

    method, which uses the variable, Jtest does not know that the variable isset by a "setter" method. It is recommended that all methods check thatthe variables have been initialized prior to their usage. However, if you arenot interested in this type of exception, you may suppress it, or tell Jtesthow to initialize that variable.

    For example,

    public class Example {private String _str;public void setString( String str ) {_str = str;}public String getUpperCase() {return _str.toUpperCase();}}

    When Jtest tests classes, it instantiates the class through the THIS argu-ment and uses that instance to test the class's instance methods. Itinstantiates the class by calling the most general constructor (the one withthe most arguments).

    You can specify which instance of the class Jtest should use by using theRestricted Inputs to choose the THIS object. In this case, the instanceshould call a method that will initialize the str member variable. Whenwriting the initialization method, instantiate the class and call the method/constructor that defines the member variable. Here is an initializationmethod that can be added to the Example class.

    public static Example makeObject () {Example m = new Example ();m.setString (new String ("this is a string"));return m;}

    To use the Restricted THIS, open Class Test Parameters> DynamicAnalysis> Test Case Generation> Automatic> Restricted Inputs .Right-click “THIS” object , choose Set Restricted Input , then enterExample.makeObject() . This argument will allow Jtest to initialize the_str variable before calling the method. If you do not want to add the

    25

  • Jtest FAQs

    makeObject method directly to your code, it can be defined in a classthat is on the CLASSPATH. For example:

    public class Inputs {public static Example makeExampleObject () {Example m = new Example ();m.setString (new String ("this is a string"));return m;}}

    In this case, the _str variable is set up in the Restricted THIS by enteringInputs.makeExampleObject()

    CoverageHow do I see coverage information for every class the original classaccesses?

    Choose Preferences> Configuration Options> Report file, then selectShow All Classes Accessed . The next report opened will include cover-age information for all classes accessed by the original class under test.

    How can I tell what was not covered by Jtest?

    The report file at the class level tells you which lines were not executed.View the report file for the class. The lines that have a ">" in front of themwere not tested by Jtest.

    What is ”partial coverage”?

    You have partial coverage when part of a statement’s instructions werenot covered.

    26

  • Jtest FAQs

    When Jtest tests a class, it tests the bytecodes of the classfiles. Byte-codes are machine instructions for the Java interpreter. A source line (inhuman readable .java ), is broken down into multiple instructions by theJava compiler. When Jtest tests a set of instructions, it records which ofthe original statement’s instructions were covered and which were not.

    If Jtest is testing a set of instructions and one instruction tells the inter-preter to jump to another instruction, then the rest of the instructions ofthe original statement will be uncovered. In this case, you have partialcoverage.

    How do I get a report file for the test cases of every class tested atthe project level?

    Report files generated at the project level do not display the test cases foreach class. Please view the test cases in the report file for individualclasses after loading them into the Class Testing UI.

    ProjectsCan Jtest count the number of classes there are in a project beforetesting?

    Yes, Jtest will not only list the number of classes in a given directory, jarfile, or zip file, but, it will also list the classes by name, and categorizethem by package name.

    To see the number of classes that Jtest will test for the project, open theProject Test Parameters window and open the Classes in the Projectbranch.

    Can Jtest show detailed coverage information from the ProjectReports generated?

    27

  • Jtest FAQs

    No. Jtest does not give detailed coverage information for every classunless the report is viewed through the Class Testing UI.

    How do I skip classes, jar files, or zip files? How do I prevent Jtestfrom testing my classes, jar files, or zip files?

    Perform the following steps:

    1. In the Project Testing UI, open the Project Test Parameters win-dow.

    2. Open the Search Parameters branch.

    3. Right-click the Skip List option and choose Edit . A Skip List dia-log appears.

    4. Enter the name of the classes or the packages that you do notwant to test, one at a time.

    For example, if the jar files contain classes in the javax.swing.*package, then enter javax.swing.* in the text field and clickthe Add button.

    5. When finished adding items to the skip list, click OK.

    For this project, Jtest will skip all the items listed in the Skip Listdialog. Otherwise, the jar files should be moved to another direc-tory that doesn't contain the classes you want to test.

    How do I disable tests for system classes?

    Open the skip list by going to the Project Test Parameters’ SearchParameters branch and double-clicking Skip List . In the Skip List thatopens, add

    java.*

    How can I specify Jtest to retest all the classes in the project?

    28

  • Jtest FAQs

    Perform the following steps:

    1. Open the Project Test Parameters window.

    2. Open the Search Parameters branch.

    3. Disable the Skip classes already tested option.

    Jtest will test classes again if they have already been tested.

    Why does Jtest find more errors when I test my project's classesindividually in the Class Testing UI than it does when I test the sameclasses as a project in the Project Testing UI?

    By default, when Jtest tests classes in the Project Testing UI, it onlydynamically tests the public classes that it finds. This means that Jtestmight not test all of the classes in the project.

    When you tell Jtest to explicitly test a class in the Class Testing UI, Jtestwill test it dynamically even if it is not public.

    If you want the Project Testing UI to report all errors that would bereported if the project's classes were tested individually in the Class Test-ing UI, tell Jtest to dynamically test the non-public classes it finds. (Thiscan be done by clicking the Project Test Parameters button in theProject Testing UI, then choosing Search Parameters> Dynamic Analy-sis ).

    When using the project tester, a maximum of ten minutes is used to testeach class. If it takes more than ten minutes to test the class, Jtest stopstesting that class and goes onto the next one. To increase the timeoutvalue in project testing, see the Project Test Parameters.

    How do I create a batch file that runs Jtest on one project followedby another?

    Use the call command in your batch file. For example, if you wantedyour runtests.bat file to test Project1, then Project2, then Project3, and soon, you would include the following commands in the file:

    29

  • Jtest FAQs

    call jtestgui -nogui -nologo -ptp Project1.ptpcall jtestgui -nogui -nologo -ptp Project2.ptpcall jtestgui -nogui -nologo -ptp Project3.ptpcall jtestgui -nogui -nologo -ptp Project4.ptp

    How do I tell the Project Testing UI to test the classes in package Xbut not test the classes in its sub-packages?

    Enter the following regular expression in the Project Testing UI’s Filter-infield:

    (X\.Y\.|X\.Z\.|X\.W)

    If you selectively want to exclude sub-packages W, Y, and Z but want totest all classes of Z and other sub-packages of Z, use the following regu-lar expression in the Filter-In field:

    (X\.Y\.[a-zA-Z_$]+$|X\.Z\.[a-zA-Z_$]+$|X\.W\.[a-zA-Z_$]+$)

    For more information about creating regular expressions, seehttp://www.cacas.org/~wes/java/syntax.html

    Troubleshooting

    Error MessagesProblem: “Error could not load dll. Problem with initialization. Processterminating.” message appears.

    Solution: This means that one of the classes Jtest is testing is attemptingto load a dll. The dll may have unresolved symbols that cannot beresolved by any dll on the system's path. First, make sure the system'spath includes every dll referenced by the java application. Second, set theClass Test Parameters Common Parameters> Directories> WorkingDirectory parameter to the directory containing the dlls referenced by theapplication.

    30

  • Jtest FAQs

    Problem: When attempting to install Jtest, an error message appearsstating, “No space available on disk” or “No space left on device,” evenwhen there is greater than 20GB free.

    Solution: This occurs on Windows NT/2000 with NTFS and very largepartitions. The solution is to reboot.

    Problem: The message "Error: unrecognized zip format: "appears when I run a test.

    Solution: Unjar or unzip the file contents, remove the jar or zip file fromthe CLASSPATH, then add the location of the classes (from the jar or zip)to the CLASSPATH.

    Problem: A message similar to the following message appears:

    Error on compilation:1) 1: Class COM.parasoft.util.JT not found in importimport COM.parasoft.util.JT;

    Solution: This message box occurs when you try to define a black-boxtest or class initialization after having added an entry to the -classpathnode in either the Class Test Parameters or the Global Test Parameters.

    To stop this message from appearing, go to the Test Parameters Windowwhere you added an entry to the classpath, remove that entry from the-classpath field, and add that same value to the -cp field.

    Problem: “jbc: corrupted file” message appears.

    Solution: Users that upgrade from Jtest 2.12 to 3.x will sometimesreceive this message when they run 3.x. This message indicates that the2.12 uninstall did not completely remove the Jtest installation directory.

    31

  • Jtest FAQs

    The solution to this problem is to close Jtest, then completely remove the“users” directory from the Jtest installation root.

    Problem: A ClassNotFoundException was reported.

    Solution: This means that when Jtest was testing your class, it could notfind one of the other classes it references. You need to determine wherethe class or classes that Jtest cannot find are located (consider that it maybe a third party library), then tell Jtest where to find these classes. Youcan indicate the location of this class by modifying the CLASSPATH envi-ronment variable on your system so that it points to the directory contain-ing the class that was not found by Jtest.

    You can also use enter CLASSPATH information in the Global TestParameters tree. Click the Global button, then indicate the classpath inCommon> java/javac like parameters> -cp (if you want to prependCLASSPATH) or Common> java/javac like parameters> -classpath (ifyou want to override CLASSPATH).

    Problem: A window labelled “Shortcut to Jtest” lingers after Jtest isclosed.

    Solution: Properties in the “Shortcut To Jtest” desktop icon specifywhether or not this window should close on exit. Make sure the Close onExit check box is selected, then re-run Jtest. A similar fix is found for theprogram group's Jtest icon.

    Problem: An “UnsatisfiedLinkError” was reported.

    Solution: This means that Jtest could not find the definition for a nativemethod. There are two reasons why this might occur:

    1. The native library isn't on the PATH.

    Solution: Put the native library on the PATH.

    32

  • Jtest FAQs

    2. The library is statically loaded by some class other than the oneJtest is testing

    Solution: Put the loadlibrary command in one of Jtest’s staticclass initialization nodes. See the Setting an Object to a CertainState topic in the User Guide for information on static class initial-ization

    Problem: "Environment out of space" message appears after runningsetenv.bat from the command line.

    Solution: Increase the environment space in Windows95 or Windows98.

    1. In the c:\config.sys file add the line:

    SHELL=C:\COMMAND.COM C:\ /p /e:8000

    where 8000 is the size of the space you want to reserve for theenvironment.

    2. Reboot your machine for the changes to take place.

    Sometimes a dialog pops up stating that the CodeWizard processcouldn’t be started. This is also because you don't have enough environ-ment space.

    Problem: An "invalid magic number" message appears when I try to testthis class.

    Solution: You are in the ClassTesting UI and attempting to open anon-class type of file using the Browse button.

    To test a jar or zip file, use the Project Testing UI.

    33

    products/jtest/manuals/v3_3/class_in.htmproducts/jtest/manuals/v3_3/class_in.htm

  • Jtest FAQs

    Problem: An "invalid search in..." or "invalid suffix" message appearswhen attempting to test the class zip, or jar file.

    Solution: You are probably trying to load a java file. If you are in theClass Testing UI, choose a .class file. If you are in the Project Testing UI,choose a .class, .zip, or .jar file.

    Problem: After the classpath is set and classes are tested, a"java.lang.ClassNotFound" error message appears.

    Solution: Check to see where the class, that Jtest cannot find, is located.Add the path to the root directory of this class to the -cp option in Jtest.

    Adding the path to the -cp option in the Class Test Parameters, ProjectTest Parameters, or Global Test Parameters windows, prepends the pathto the classpath environment variable.

    Problem: After entering jtestgui from the command line, the message“Exception in thread main java.lang.NoClassDefFoundError: " appears.

    Solution:

    1. Use a shorter name for the directory names with spaces.

    For example: if the directory \\c:\program files\parasoft appears inyour CLASSPATH with or without quotations, change the direc-tory name in that path to a shorter dos name c:\progra~1\para-soft.

    2. Remove any quotations that might be surrounding one of thedirectory names set in the CLASSPATH variable.

    For example: if the directory c:\program files\parasoft appears atthe end of your CLASSPATH variable, change the CLASSPATHby getting rid of the quotations around that last directory listed.

    34

  • Jtest FAQs

    Problem: The message "This feature is only available with the projecttesting add-on, please contact..." appears after I click Project in the ClassTesting UI.

    Solution: This is a license problem. Contact the representative whoissued the license and ask for another one.

    Problem: After typing setenv at the command prompt, the message "toomany parameters" appears.

    Solution: In the autoexec.bat file, look for any spaces in the PATHvariable and change the name of the directory with the space to a dosname. Back up the old autoexec.bat file and use the revised one.Restart the machine to have changes take affect. Run Jtest again onSimple.class to make sure static analysis works.

    For example, if the PATH is: %PATH%;"d:\Visual-Cafe\Bin;d:\VisualCafe\Java2\Bin;C:\Program Files\Common Files\Symantec Shared"

    You should change the PATH to: %PATH%;"d:\Visual-Cafe\Bin;d:\VisualCafe\Java2\Bin;C:\Progra~1\Common~1\Symant~1"

    Problem: I’m running Jtest on Solaris 2.6; after I click the Start button, Ireceive a message that says “"ld.so.1: jtest/bin/cwj: fatal: libgen.so.1:open”.

    Solution: Upgrade to Solaris 2.7 or 2.8 and re-run Jtest; Jtest does notsupport Solaris 2.6.

    Problem: When I try to run Jtest on Solaris I receive the following mes-sage: “Must install a Solaris patch to run this version of the Java runtime."

    35

  • Jtest FAQs

    Solution: Jtest 3.31 uses the JRE 1.2 to display its UI. To ensure that theJava runtime environment is able to run on your machine, you need toinstall a patch from Sun. Download a patch athttp://java.sun.com/products/jdk/1.2/install-solaris-patches.htmlthen install it as described on that site.

    ProblemsProblem: Jtest runs out of memory resources when testing very largeprojects.

    Solution: First, run Jtest on a machine with at least 128MB RAM; this isthe minimum amount of RAM recommended if you are going to runproject tests.

    Second, break the test run into several smaller tests. Instructions on howto do this can be found in the Testing a Large Project section of the JtestUser Guide.

    Problem: When I click Set in the Jtest license window, I receive a dialogbox that says “permission denied.”

    Solution: The license file in the Jtest installation directory was not writ-able by the current Jtest user when the product tried to write to that file.Either install the license as the owner of that file (which can be found byusing ls -l on the license file) or change the license file to be writableby the current user.

    Problem: The source viewer displays the incorrect line.

    Solution: This occurs when the source file is newer than the class file.The source was edited --but not recompiled-- before testing. To see thecorrect line, recompile your source and re-test the class with Jtest

    36

    products/jtest/manuals/v3_3/large.htm

  • Jtest FAQs

    Problem: Jtest is configured to create and execute test cases, but it doesnot create test cases.

    Solution: In order to test your class, Jtest must first instantiate an objectof that class. Then it can test all of the instance methods of the class. Seethe NoTestCases.java file for a description of how to tell Jtest to gen-erate a good instance so that it can test it. NoTestCases.java islocated under the installation root, in the examples/dynamic/whitebox directory.

    Problem: The dialog “source not found” appears while testing a class or aproject.

    Solution: The .java file for that class under test is not in the same direc-tory as the .class file, or there is no source code. To indicate the loca-tion of your source.

    1. Stop testing.

    2. Point Jtest to the parent directory of the source files (under theCommon Parameters branch, in either the Class Test Parame-ters or the Project Test Parameters window).

    3. Click OK in the dialog box.

    4. Another dialog appears asking you to choose between 3 options.If you do not have the source code for any of the classes, youshould choose option B, to skip static analysis for all missingsource code. If you are not sure, choose option A or C.

    Problem: When I try to use an Inputs class, Jtest says the class is notfound.

    Solution: This happens when you attempt to use a class outside of theenvironment to generate test data inputs. The user will get a red diamondin the argument field and it will say "Inputs class not found".

    The workaround is to add to the imports the class itself. For example:

    37

  • Jtest FAQs

    import Inputs;

    This works around a bug in the 'javac' Java compiler.

    Problem: Jtest does not launch from the shortcut icon.

    Solution: Open a dos window and go to the Jtest installation directory.Enter setenv , and then enter jtestgui .

    If the message returned after jtestgui is "java.lang.NoClassDefFoundEr-ror", please see the FAQ about NoClassDefFoundError.

    If no message is returned and Jtest doesn't launch, it could be related topermission problems. Check to see if you have write permission to theJtest installation directory.

    Problem: Jtest found an error in my class, but when I click the stack traceto view the error, the source viewer doesn't show the correct line. Why?

    Answer: You are seeing the incorrect line because the source file isnewer than the class file. The source was edited-- but not recompiled--before testing. To see the correct line, recompile your source and re-testthe class with Jtest.

    Problem: Jtest says my method has no branches. What does the termbranches mean?

    Answer: Branches are conditional statements in which, based on theargument to the conditional statement, there are two paths to take.

    For example, an IF statement has two branches: one true and one false.When Jtest says that a method has no branches, it means the methoddoesn't have any conditional statements.

    38

  • Jtest FAQs

    UNIX

    Problem: Downloaded file won’t extract on Solaris 7.

    Solution: When downloading Jtest for Solaris 7, please make sure thatthe filename ends with the extension .class.Z (the default name isjtest_solaris.class.Z ). Some web browsers display and/or savethe file without the .Z extension. If this happens, rename the file so that itends with .Z either before you start downloading, or after you finish. Oth-erwise, you will not be able to uncompress the file, because the uncom-press utility will not recognize it as a compressed file.

    This problem has been seen in the following browsers: *

    Netscape 4.51 for Solaris, Netscape 4.7 for Solaris, Netscape 4.7 for Win-dows (only displays the file incorrectly; the file is saved correctly)

    The following browsers seem to be unaffected: *

    Netscape 4.74 for Windows, Internet Explorer 5.0 for Windows

    * not a complete listing

    Problem: When I attempt to run Jtest from my xterm, the message "ErrorConnecting to X11 Server. Could not open display." appears.

    Solution: This occurs when the current xterm doesn't have Xprivileges toopen an Xwindow on the target machine's display. Set the DISPLAY envi-ronment variable to the host computer on which Jtest will be displayed.

    Problem: A "source: not found" message appears after entering sourcejtestenv while attempting to set up the environment for running Jtest onSolaris.

    Solution:

    1. Determine which shell is being used to run source jtestenv .

    39

  • Jtest FAQs

    40

    2. If you are not in the c-shell (csh), the environment variables in thejtestenv file must be set up according to the shell that you areusing.

    Problem: When I perform black-box testing, a blank error dialog box (anempty dialog box, a dialog box with no text, or a dialog box with a stopsign and no message) appears for each input given.

    Solution: You need to place tools.jar and rt.jar from their JDKinstallation on their CLASSPATHbefore launching Jtest.

    1. Close Jtest.

    2. In the console where Jtest was launched, place tools.jar andrt.jar on the CLASSPATHin this order: set the path totools.jar (...\jdkXXX\lib\tools.jar ), then set the pathto rt.jar (...\jdkXXX\jre\lib\rt.jar ).

    3. Start Jtest again from the console where the CLASSPATHwas justset.

    4. Test the class again with the user-defined inputs

    There should be no error messages.

    How do I modify environment variables for my Solaris csh environ-ment?

    To append to an environment variable, enter

    setenv PATH $PATH':'

    For example, to add jtest/bin to the LD_LIBRARY_PATHvariable:

    setenv LD_LIBRARY_PATH $LD_LIBRARY_PATH':'jtest/bin

    To list the path contents of the variable, enter

    echo $

    To list all the environment settings, enter setenv .

  • Jtest FAQs

    Problem: When I start Jtest I get messages in the console window thatsay, “Could not write token log file.”

    Solution: You must have write permissions in the directory where Jtest isinstalled. Have your system administrator give you write permissions tothe Jtest installation directory.

    Last revised 4/17/01.

    41

    Jtest FAQsGeneralCustomizing Test ParametersStatic AnalysisWhite-Box TestingBlack-Box TestingCoverageProjectsTroubleshootingError MessagesProblemsUNIX