[SailfishDevel] QtQuickTest tests imports and test/main code locations while there's no conditional import in QML

Artem Marchenko artem.marchenko at gmail.com
Mon Oct 21 11:21:19 UTC 2013


Hi All

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-emulator (I suspect situation is similar on
Android, iOS and even MacOS X as well), 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 none of which I like much, but maybe
one of them could somehow be improved?

0. 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

1. 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

2. 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?

Cheers,
Artem.

-- 
Artem Marchenko
http://agilesoftwaredevelopment.com
http://twitter.com/AgileArtem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20131021/8ea57cde/attachment.html>


More information about the Devel mailing list