GitHub - dasalgadoc/testing-in-java: Project to explore basic test techniques in Java · GitHub
Skip to content

dasalgadoc/testing-in-java

Repository files navigation

🚀 🍮 Testing techniques in Java 🍮 🚀

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.

🧲 Environment Setup

🛠️ Needed tools

  1. Java 17
  2. Maven
  3. Docker and Docker compose (I use Docker version 23.01.1 and docker-compose v2.17.0)

🏃🏻 Application execution

  1. Make sure to download all Needed tools
  2. Clone the repository
  3. Build up maven project
mvn dependency:resolve
  1. Compile the project
mvn compile && mvn package
  1. Run test, this step will start the docker environment (make sure ports 8080 and 3306 is not in use)
make all
  1. Enjoy! 😎

📚 References

✏️ Notes

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.

🥒 Cucumber instructions

  1. 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>
  1. Create a feature file in src/test/features
  2. 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
}
  1. Run the test class

🙅🏻‍♂️ Exclude testing

Using maven, exclude some test is easy, just subtract the suffix Test from the class name.

About

Project to explore basic test techniques in Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages