Move the unit tests from commandlinerunner to separate project

See gh-142
This commit is contained in:
Moritz Halbritter
2022-11-24 11:44:05 +01:00
parent 83ab552cfc
commit 4978fec9f4
8 changed files with 58 additions and 15 deletions

View File

@@ -7,9 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class CommandlinerunnerApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(CommandlinerunnerApplication.class);
System.setProperty("main.ran", "true");
application.run(args);
SpringApplication.run(CommandlinerunnerApplication.class, args);
}
}

1
boot/tcf/README.adoc Normal file
View File

@@ -0,0 +1 @@
Tests if Spring Boot's TestContext Framework is working

16
boot/tcf/build.gradle Normal file
View File

@@ -0,0 +1,16 @@
plugins {
id 'java'
id 'org.springframework.boot'
id 'org.springframework.aot.smoke-test'
id 'org.graalvm.buildtools.native'
}
dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
implementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework.boot:spring-boot-starter-test")
appTestImplementation(project(":aot-smoke-test-support"))
appTestImplementation("org.awaitility:awaitility:4.2.0")
}

View File

@@ -0,0 +1,15 @@
package com.example.boot.tcf;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BootTcfApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(BootTcfApplication.class);
System.setProperty("main.ran", "true");
application.run(args);
}
}

View File

@@ -1,4 +1,4 @@
package com.example.commandlinerunner;
package com.example.boot.tcf;
import java.util.List;
@@ -7,19 +7,12 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.UseMainMethod;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = WebEnvironment.NONE, useMainMethod = UseMainMethod.ALWAYS, args = "--test.args=1")
class CommandlinerunnerApplicationTests {
@Test
void mainShouldRun() {
String property = System.getProperty("main.ran", "false");
assertThat(property).isEqualTo("true");
}
@SpringBootTest(webEnvironment = WebEnvironment.NONE, args = "--test.args=1")
class ArgsTest {
@Test
void shouldPassArgs(@Autowired ApplicationArguments applicationArguments) {

View File

@@ -0,0 +1,20 @@
package com.example.boot.tcf;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.UseMainMethod;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = WebEnvironment.NONE, useMainMethod = UseMainMethod.ALWAYS)
class MainMethodTests {
@Test
void mainShouldRun() {
String property = System.getProperty("main.ran", "false");
assertThat(property).isEqualTo("true");
}
}

View File

@@ -1,4 +1,4 @@
package com.example.commandlinerunner;
package com.example.boot.tcf;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

View File

@@ -1,4 +1,4 @@
package com.example.commandlinerunner;
package com.example.boot.tcf;
import org.junit.jupiter.api.Test;