Bana herhangi bir QT test kodu ve Cmake ile inşa edilen ve CTest ile koşan bir CMakeLists.txt örneği verebilir misiniz? Hiçbir şey bulamıyorum!CMake ile Qt Testleri Oluşturun
-Kurtis
Bana herhangi bir QT test kodu ve Cmake ile inşa edilen ve CTest ile koşan bir CMakeLists.txt örneği verebilir misiniz? Hiçbir şey bulamıyorum!CMake ile Qt Testleri Oluşturun
-Kurtis
Charm (Test/CMakeLists.txt) alınan bir örnek:
SET(TestApplication_SRCS TestApplication.cpp)
SET(TEST_LIBRARIES CharmCore ${QT_QTTEST_LIBRARY} ${QT_LIBRARIES})
SET(SqLiteStorageTests_SRCS SqLiteStorageTests.cpp)
QT4_AUTOMOC(${SqLiteStorageTests_SRCS})
ADD_EXECUTABLE(SqLiteStorageTests ${SqLiteStorageTests_SRCS})
TARGET_LINK_LIBRARIES(SqLiteStorageTests ${TEST_LIBRARIES})
ADD_TEST(NAME SqLiteStorageTests COMMAND SqLiteStorageTests)
normal yürütülebilir tek fark, ADD_TEST makro çağrı olmasıdır. Örneğe bakınız. Bunu eylemde görmek için cazibe.
İşte, cmake 2.8.11 ve Qt5.2'yi kullanma örneğidir. Cmake'nin şimdi test dosyalarını alt kısımdaki bir .moc-include ile desteklediğini unutmayın.
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.11)
project(foo)
enable_testing()
# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Test REQUIRED)
add_executable(foo foo.cpp)
add_test(foo foo)
target_link_libraries(foo Qt5::Test)
foo.cpp:
#include <QTest>
class Foo : public QObject {
Q_OBJECT
private slots:
void t1() { QVERIFY(true); }
};
QTEST_MAIN(Foo)
#include "foo.moc"
+1. –
Kodu derlemek için CMakeList'in son satırını düzenlemeliydim: target_link_libraries (foo Qt5 :: Widgets Qt5 :: Test). Qt5 için +1. Benim olup olmadığından emin değilim, ya da aslında bir hatadır, bu yüzden cevabı düzenlemiyorum. – cauchy
@cauchy: elbette, eğer testiniz QtWidgets gerektiriyorsa, şu şekilde bağlanmalıdır ...: P – Smar
mükemmeldir. Muhteşem. Çok teşekkürler. –
Umarız bu, bir kimseyi yoldan bir süre daha kurtaracak - bu sayfaya göre (http://qt-project.org/wiki/Writing_Unit_Tests): "CMake'in qtest dosyalarını alt." –
Bu durumda, test dosyalarınızı da otomatik olarak hatırlamanız gerekir. Qt5 ile kullanım için – jackyalcine