Forum Discussion

hugo_soares's avatar
hugo_soares
Occasional Contributor
11 years ago

USEUNIT in shared script unit is looked for wrongly

I have the project A that has a shared script unit (unitb.1) from project B. This unit (from project B) uses another script unit belonged to his parent project. (unitb.2)

The problem happens while I running Project A's script unit that depends unitb.1: TestComplete is looking for unitb2 into Project A, and I think it should look into Project B.

The only option for code reusing among sibling projects is Copy and Paste?!?!?!?
  • Really, what you should do is move shared procedures to a third unit. Call that unit "Framework" or something similar, and reference it from both your A and B.
  • hlalumiere's avatar
    hlalumiere
    Regular Contributor
    Really, what you should do is move shared procedures to a third unit. Call that unit "Framework" or something similar, and reference it from both your A and B.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    TestComplete does not use anything like path or environment variables search for the script units. Personally I consider such implementation to be correct as it eliminates the problems when for some reason some other script unit is used instead of one that you are expecting to be used.



    The actual behavior is quite logical, as for me:

    -- All script units that are needed for the test code must be included in the project. Those script units are not necessarily must be in the same folder, but may already exist and be located in some external folder (named, say, ReusableCode). Such existing script units may be added to the project by using the 'Add Existing Item...' context menu command for the project's Scripts node;

    -- If the script unit calls the code from another script unit, this another script unit must be referenced in the calling unit via USEUNIT (or equivalent) statement;

    -- When you deploy test project that uses script units from ReusableCode folder to another location, you must preserve the relative folders hierarchy.
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Hugo,



    From here in the documentation



    "Circular references are not allowed in JScript, C++Script and C#Script. Circular links in these languages may cause errors in the jscript.dll library (C++Script and C#Script are based on JScript and also use this DLL) and these errors can cause other errors in TestComplete.


    As for DelphiScript and VBScript units, they can refer to each other. In other words, circular references are allowed. For instance, if you need to call scripts declared in UnitA from UnitB, and to call scripts declared in UnitB from UnitA, you must add references to both units --"



    Sincerely


  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Hugo, I did a quick test on how you have your project set up and I think the problem you are having is that when tests within a Project run, Test Complete only looks in that Project for referenced Script Units.


     


    For example, if the following Projects/Script Units exist:


     


    ProjectA


    Unit1A


     


    ProjectB


    Unit1B


     


    ProjectC


    Unit1C


     


    and the following references are realised with //USEUNIT


     


    1. ProjectB.Unit1B references ProjectA.Unit1A


    2. ProjectC.Unit1c references ProjectB.Unit1B


     


    then, in order for ProjectC.Unit1c to run, ProjectC must have references to both ProjectB.Unit1B AND ProjectA.Unit1A because ProjectC has no way of evaluating that the Script Unit Unit1A that Script Unit ProjectB.Unit1B references exists in ProjectA.


     


    Hope this helps,


    Phi Baird