Important: Please read the Qt Code of Conduct -

QtQuickTest tests imports and test/main code locations

  • I have a nearly pure QML projects and want to have some QtQuickTest tests for it too. So the standard approach for organizing a project would be then something like:

    • MyApp - subdirs project
      • src - actual app
      • test - tests

    When deployed to the device (Jolla Sailfish in my case, but I suspect situation is similar on Android, iOS and even MacOS X), the directory structure is likely to be different (and test package is not to be passed to the app store, so it's good if tests are deployed somehow separately). The structure that looks logical to me is something like the following:
    /usr/share/MyApp - application, deployed by the MyApp package
    /usr/share/tst-MyApp - tests, deployed by the MyApp-tests package

    The problem
    At run-time test code needs to import "../MyApp" while during editing time for QtCreator to use proper code completion and highlights (very useful during development), you need to import "../src"

    How could I have imports working both at run time and in Creator while having sane project-deployment directories structure?

    Possible options
    I was able to figure out a few options non of which I like much, but maybe one of them could somehow be improved?

    1. Just forget about the whole thing. Import the run-time directories and code carefully in Creator. Or temporarily change import while coding and remember to change it back when building

    2. Restructure project directories so that app folder has same name as deploment folder:

    • MyApp - subdirs project
      • MyApp - actual app. Directory name is precisely identical to the deployment folder
      • test - tests

    /usr/share/MyApp - app code on device
    /usr/share/tst-MyApp - test code on device

    then import will always be just import "../MyApp", but.. app folder should really be called src, and it's sort of weird to have top dir and lower level dir have the same name

    1. Use import "../src" and somehow hack the import resolution in the test harness so that "../src" would be translated to "../MyApp" at runtime. I think I've read somewhere that it is possible to override the import search somehow.

    What would you do?

Log in to reply