Jellyfin Desktop uses Qt Test for unit testing.
Tests are built automatically when you build the project:
cmake -B build
cmake --build buildRun all tests using CTest:
cd build
ctestOr run individual test executables directly:
cd build
./tests/test_systemcomponentTests are located in the tests/ directory. To add a new test:
- Create a test file in
tests/(e.g.,test_mycomponent.cpp) - Use
QTEST_APPLESS_MAINfor headless unit tests - Add the test to
tests/CMakeLists.txt
Example test structure:
#include <QtTest/QtTest>
#include "../src/mycomponent/MyComponent.h"
class TestMyComponent : public QObject
{
Q_OBJECT
private slots:
void testMyFunction_data();
void testMyFunction();
};
void TestMyComponent::testMyFunction_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("expected");
QTest::newRow("test case 1") << "input1" << "output1";
QTest::newRow("test case 2") << "input2" << "output2";
}
void TestMyComponent::testMyFunction()
{
QFETCH(QString, input);
QFETCH(QString, expected);
QString result = MyComponent::myFunction(input);
QCOMPARE(result, expected);
}
QTEST_APPLESS_MAIN(TestMyComponent)
#include "test_mycomponent.moc"For more information on Qt Test, see the Qt Test documentation.