Skip to content

Commit

Permalink
Compile application classes before test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored and gsmet committed Nov 15, 2022
1 parent 5aa3f11 commit 868a4c9
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ private void periodicTestCompile() {
scanLock.lock();
TestScanningLock.lockForTests();
try {
ClassScanResult changedTestClassResult = compileTestClasses();
ClassScanResult changedApp = checkForChangedClasses(compiler, DevModeContext.ModuleInfo::getMain, false, test,
true);
ClassScanResult changedTestClassResult = compileTestClasses();
if (changedApp.compilationHappened) {
if (testCompileProblem != null) {
testSupport.testCompileFailed(testCompileProblem);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.quarkus.vertx.http.testrunner;

import java.util.function.Function;
import java.util.function.Supplier;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.dev.testing.TestScanningLock;
import io.quarkus.test.ContinuousTestingTestUtils;
import io.quarkus.test.ContinuousTestingTestUtils.TestStatus;
import io.quarkus.test.QuarkusDevModeTest;

public class ChangeSourceAndTestAtOnceTestCase {

@RegisterExtension
static QuarkusDevModeTest test = new QuarkusDevModeTest()
.setArchiveProducer(new Supplier<>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class).addClasses(CoupledService.class)
.add(new StringAsset(ContinuousTestingTestUtils.appProperties("quarkus.test.type=unit")),
"application.properties");
}
})
.setTestArchiveProducer(new Supplier<>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class).addClasses(CoupledET.class);
}
});

@Test
public void testChangeSourceAndTestAtOnce() throws InterruptedException {
ContinuousTestingTestUtils utils = new ContinuousTestingTestUtils();
TestStatus ts = utils.waitForNextCompletion();
Assertions.assertEquals(1L, ts.getTestsPassed());
TestScanningLock.lockForTests();
try {
test.modifySourceFile(CoupledService.class, new Function<String, String>() {
@Override
public String apply(String s) {
return s.replace("service", "newService");
}
});
test.modifyTestSourceFile(CoupledET.class, new Function<String, String>() {
@Override
public String apply(String s) {
return s.replace("service", "newService");
}
});

} finally {
TestScanningLock.unlockForTests();
}
ts = utils.waitForNextCompletion();
Assertions.assertEquals(1L, ts.getTestsPassed());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.vertx.http.testrunner;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CoupledET {

@Test
public void unitStyleTest2() {
Assertions.assertEquals("unit", CoupledService.service());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkus.vertx.http.testrunner;

public class CoupledService {

public static String service() {
return "unit";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -774,4 +774,16 @@ public QuarkusDevModeTest setAllowFailedStart(boolean allowFailedStart) {
this.allowFailedStart = allowFailedStart;
return this;
}

static class ChangeSet {
final String name;
final Function<String, String> mutator;
final Path path;

ChangeSet(String name, Function<String, String> mutator, Path path) {
this.name = name;
this.mutator = mutator;
this.path = path;
}
}
}

0 comments on commit 868a4c9

Please sign in to comment.