Gradle Derleme Desteği
TestFly, kutudan çıktığı gibi Gradle ile çalışır — Maven Central'daki JAR, derleme aracından bağımsızdır. Bu sayfa, hem Groovy DSL (build.gradle) hem Kotlin DSL (build.gradle.kts) için önerilen kurulumu kapsar.
Adım 1 — Bağımlılığı ekleyin
- Groovy DSL (build.gradle)
- Kotlin DSL (build.gradle.kts)
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'io.github.hakanngul:testfly:1.0.7'
}
plugins {
java
}
repositories {
mavenCentral()
}
dependencies {
testImplementation("io.github.hakanngul:testfly:1.0.7")
}
Adım 2 — Test yürütmeyi yapılandırın
TestNG (varsayılan koşturucu)
- Groovy DSL
- Kotlin DSL
test {
useTestNG {
// İsteğe bağlı: bir testng.xml paket dosyasını işaret edin
// suites 'src/test/resources/testng.xml'
}
// Sistem özelliklerini iletin, böylece -Denv=staging CLI'dan çalışır
systemProperties System.properties
// Test çıktısını konsolda göster
testLogging {
events 'passed', 'skipped', 'failed'
showStandardStreams = false
}
}
tasks.test {
useTestNG {
// İsteğe bağlı: bir testng.xml paket dosyasını işaret edin
// suites("src/test/resources/testng.xml")
}
// Sistem özelliklerini iletin, böylece -Denv=staging CLI'dan çalışır
systemProperties(System.getProperties().mapKeys { it.key.toString() })
testLogging {
events("passed", "skipped", "failed")
showStandardStreams = false
}
}
JUnit 5 köprüsü
BaseJUnit5Test veya @EnableTestFly kullanıyorsanız:
- Groovy DSL
- Kotlin DSL
dependencies {
testImplementation 'io.github.hakanngul:testfly:1.0.7'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'
}
test {
useJUnitPlatform()
systemProperties System.properties
}
dependencies {
testImplementation("io.github.hakanngul:testfly:1.0.7")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
}
tasks.test {
useJUnitPlatform()
systemProperties(System.getProperties().mapKeys { it.key.toString() })
}
Adım 3 — Yapılandırma dosyası
Proje kökünde (build.gradle ile aynı düzeyde) testfly.yml oluşturun:
execution:
mode: local
baseUrl: https://example.com
browser:
name: chrome
headless: true
timeouts:
explicit: 10
pageLoad: 30
retry:
enabled: true
maxAttempts: 2
Testleri çalıştırma
# Tüm testleri çalıştır
./gradlew test
# Tek bir test sınıfını çalıştır
./gradlew test --tests "com.example.LoginTest"
# Tek bir test metodunu çalıştır
./gradlew test --tests "com.example.LoginTest.validLogin"
# Bir ortam profiliyle çalıştır
./gradlew test -Denv=staging
# Birden çok JVM argümanı ilet
./gradlew test -Dbrowser.name=firefox -Dbrowser.headless=true
Test raporu konumları
| Rapor türü | Gradle yolu |
|---|---|
| HTML raporu (TestFly) | build/testfly-report/index.html |
| JUnit XML (TestFly) | build/test-results/test/TEST-TestFly.xml |
| Gradle'ın kendi HTML raporu | build/reports/tests/test/index.html |
| Allure sonuçları (etkinse) | build/allure-results/ |
TestFly, bir build/ dizininin var olup olmadığını ve target/ dizininin var olmadığını kontrol ederek Gradle'ı otomatik algılar, ardından XML'i build/test-results/test/ dizinine yazar. Gerekirse -Dtestfly.reports.dir=path/to/dir ile geçersiz kılın.
Paralel yürütme
Gradle ile paralel çalıştırmalar için, testfly.yml ile birlikte test görevini yapılandırın:
- Groovy DSL
- Kotlin DSL
test {
useTestNG()
maxParallelForks = 4 // Gradle worker süreçleri
systemProperties System.properties
}
tasks.test {
useTestNG()
maxParallelForks = 4
systemProperties(System.getProperties().mapKeys { it.key.toString() })
}
execution:
parallel: methods
threadCount: 4
İsteğe bağlı bağımlılıklar
Bunlar TestFly JAR'ında compileOnly / isteğe bağlıdır — yalnızca ilgili özelliği kullanıyorsanız ekleyin:
| Özellik | Bağımlılık |
|---|---|
Excel @TestData | testImplementation 'org.apache.poi:poi-ooxml:5.4.0' |
| E-posta doğrulama (IMAP) | testImplementation 'com.sun.mail:jakarta.mail:2.0.2' |
| Cucumber | testImplementation 'io.cucumber:cucumber-java:7.20.1' + testImplementation 'io.cucumber:cucumber-junit-platform-engine:7.20.1' |
Tam örnek proje
Minimal çalışan bir Gradle projesi (Groovy DSL, TestNG):
my-tests/
├── build.gradle
├── testfly.yml
└── src/
└── test/
└── java/
└── com/example/
└── LoginTest.java
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'io.github.hakanngul:testfly:1.0.7'
}
test {
useTestNG()
systemProperties System.properties
testLogging { events 'passed', 'skipped', 'failed' }
}
import io.testfly.test.BaseTest;
import org.openqa.selenium.By;
import org.testng.annotations.Test;
public class LoginTest extends BaseTest {
@Test
public void validLogin() {
open("/login");
find("input#username").type("admin");
find("input#password").type("secret");
find("button[type='submit']").click();
assertThat(By.id("dashboard")).isVisible();
}
}
./gradlew test