function outTestObj = clone(inTestObj, varargin)
%

%   Copyright 2008-2016 The MathWorks, Inc.

    outTestObj  = [];
    if ~isempty(varargin) 
        outTestObj = varargin{1};
    end
    inId = inTestObj.id;
    modelcov = cv('get', inId, '.modelcov');
    rootPath = cv('GetTestRootPath', inId);
    modelName = '';
    if modelcov ~= 0
        if SlCov.CovMode.isGeneratedCode(cv('get', modelcov, '.simMode'))
            modelName = cv('get', modelcov, '.unmangledName');
        else
            modelName = cv('GetModelcovName',modelcov);
        end
    end
    ownerModel = cv('get',inId ,'.ownerModel');

    if isempty(outTestObj)
        % Get current test properties
        if isempty(rootPath) || ~isempty(ownerModel)
            tstPath = modelName;
        else
            tstPath = [modelName '/' rootPath];
        end

        outTestObj = cvtest(tstPath);
    end
    copySettings(outTestObj, inTestObj);
