This repository contains a project to explore basic test techniques in Java.
Notes:
- All test are passing, even the bad ones.
- To explore similar techniques in Go, please check this repository also, you will find theoretical information about testing.
- If you'll use this repository for study. I strongly recommend to follow commit by commit.
- Java 17
- Maven
- Docker and Docker compose (I use Docker version 23.01.1 and docker-compose v2.17.0)
- Make sure to download all Needed tools
- Clone the repository
- Build up maven project
mvn dependency:resolve- Compile the project
mvn compile && mvn package- Run test, this step will start the docker environment (make sure ports 8080 and 3306 is not in use)
make all- Enjoy! 😎
Mockito spy allow to modify the behavior of a method in a class. It is useful when you want to test a method that calls other methods in the same class.
- Add dependencies
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>- Create a feature file in
src/test/features - Create a Java Class to receive steps
// Annotations imports
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
@Given("I send a GET request to {string}")
public void i_send_a_get_request_to(String endpoint) {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}4.Create a Test class to run the feature
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/features",
glue = "<PACKAGE WHERE STEP 2 CLASS EXISTS>")
@SpringBootTest
public class HttpStudentGetterTest {
// No body needed
}- Run the test class
Using maven, exclude some test is easy, just subtract the suffix Test from the class name.
