Skip to content

Commit

Permalink
add tests 💃
Browse files Browse the repository at this point in the history
  • Loading branch information
alina-yur committed Feb 20, 2024
1 parent c3f3908 commit 4078e46
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It's a standard native compilation command that would work on any Spring Boot ap

# Dev Mode

For development purproses, you can speed up native builds by passing the `-Ob` flag: either via the command line, or in the Native Maven plugin:
For development purposes, you can speed up native builds by passing the `-Ob` flag: either via the command line, or in the Native Maven plugin:

```
<plugin>
Expand Down Expand Up @@ -83,4 +83,16 @@ There are several levels of optimizations in Native Image, that can be set at bu
- `-pgo`: Using PGO will automatically trigger `-O3` for best performance.


## Testing 🧪

GraalVM's Native Build Tools support testing applications as native images, including JUnit support. The way this works is that your tests are compiled as native executables to verify that things work in the native world as expected. Test our application with the following:

```mvn -PnativeTest test```

`HttpRequestTest` will verify that our application returns the expected message.

Native testing recommendation: you don't need to test in the mode all the time, especially if you are working with frameworks and libraries that support Native Image – usually everything just works. Develop and test your application on the JVM, and test in Native once in a while, as a part of your CI/CD process, or if you are introducing a new dependency, or changing things that are sensitive for Native Image (reflection etc).

## Using libraries

## Monitoring 📈
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<buildArgs>
<buildArg>--gc=G1</buildArg>
<buildArg>--pgo=${project.basedir}/default.iprof</buildArg>
<buildArg>-march=native</buildArg>
<buildArg>-march=native</buildArg>
</buildArgs>
</configuration>
</plugin>
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/com/example/demo/HttpRequestTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.demo;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class HttpRequestTest {

@LocalServerPort
private int port;

@Autowired
private TestRestTemplate restTemplate;

@Test
void greetingShouldReturnMessage() throws Exception {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/hello",
String.class)).contains("Hello from GraalVM and Spring!💃");
}
}

0 comments on commit 4078e46

Please sign in to comment.