How do I test my lib?
-
I am creating a subdirs project which will have several libs. Some of these are open source and come with tests, so I want to include the tests in the project.
The first was simple as the source contains a command-line executable dedicated to doing a quick test. I made that into one of my sub projects.
The next creates several command-line executables one of which is used for testing, but the testing is done by a bit of bash type script:
check-local:
rm -f testout
./djpeg -dct int -ppm -outfile testout.ppm $(srcdir)/testorig.jpg
./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg
./cjpeg -dct int -outfile testout.jpg $(srcdir)/testimg.ppm
./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg
./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm
./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg
cmp $(srcdir)/testimg.ppm testout.ppm
cmp $(srcdir)/testimg.bmp testout.bmp
cmp $(srcdir)/testimg.jpg testout.jpg
cmp $(srcdir)/testimg.ppm testoutp.ppm
cmp $(srcdir)/testimgp.jpg testoutp.jpg
cmp $(srcdir)/testorig.jpg testoutt.jpgCan I do something like that in Qt?
And how do I declare the resource files (*.jpg) that I will need? They will need to be copied to wherever the executable get executed..... -
What is that you wanted in Qt ? Question is not very clear. Do you want execute one by one ?give more details.
-
@dheerendra OK thinking more clearly about this I can narrow down my requirement.... part of the problem is that I am new to this build system and so do not know the correct questions to ask.
What I would like to do is:
- build a command-line executable
- run the executable on a particular file (input file)
- compare the resulting file to a file representing the expected result (reference file), and report/throw an error if they differ.
So I guess there are several gaps in my knowledge:
- how do I know where my input file is - I can store it in git but the app is run in a different directory. Presumably where it is built, and that may vary. So somehow I need to make sure that my input and reference files wind up in the directory with the app.
- How do I run a system command (in this case file compare) automatically after the app. Is this even a thing in Qt?
- How do I flag up an error result
I am sort of thinking of a target (subdir app) that runs and its output tells me that the lib built fine. Maybe I am expecting too much of this build system -gradle does this testing type thing, but then gradle does not give me the multiplatform support that Qt does.
-
Hi,
You are likely looking for the QtTest module.
Your reference file(s) should be part of the sources. You can, for example, create a
define
that will contain the absolute path to your resource for the test for find it.