![]() given: The definition of the input test data.The idea is to use given, when, and then clauses to divide the test parts. That structure is similar to the structure defined in Behavior Driven Development (BDD). Unit tests created using the Spock framework have a structure to follow. Set the directory to the same groovy directory created before. Set the same values as shown in the image below.Īfter setting the test parameters, another window will pop up to choose the destination directory of the test. option.Īnother window will pop up to set some test parameters. option (or press alt + insert if you are using the default configuration of IntelliJ). To create a test class, right-click the BMICalculator class name within the code and go to the Generate. Now it’s time to create the test class for the target class. The equation and table below show how to calculate the BMI value and the interval for each BMI category.Įquation: BMI value = x 10,000 ![]() That calculator receives a person's height and weight and returns the BMI category. ![]() In this tutorial, I’ll use a Body Mass Index (BMI) calculator to be the target application of unit tests. Right-click on the groovy directory and go to Mark Directory As->Test Sources Root.Right-click on the test folder (which is within the src folder of your project directory) and choose the New->Directory option.It is a good practice to keep them separated from the Java tests. The final step is to create the test folder to store Spock tests. ![]() To do so, go to the Maven menu in the top right corner of IntelliJ IDEA and click on the Reload All Maven Projects button, highlighted in the image below. To do so, add the following lines anywhere inside the tag at your pom.xml file located in the root directory of the project:Īfter adding this dependency, you’ll need to reload the project’s dependencies. After indexation, it is time to pull the Spock maven dependency into our project. Wait a few seconds for the IDE to index the imported files. Once there, click on File->Open at the top left corner and choose the extracted archive. To import the project into IntelliJ IDEA, do the following steps: The final result of the initializer configuration is like the image below:Ĭonfigure the Application using IntelliJ IDEAĪfter clicking on Generate at the Spring Initializr, the website downloads a.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |