A.6. How to use the chapter code in Eclipse

Here I provide step-by-step instructions on how to import a chapter in Eclipse and run a Spock test. This section refers to chapter 1, but all chapters work in the same way.

Check out the source code and place it somewhere on your local filesystem.[2] Then, from Eclipse, choose File > Import and select a Maven project, as shown in figure A.8.

2

Your Eclipse workspace is a good place as it will make things easier.

Figure A.8. Importing as a Maven project

Navigate to the folder that contains the chapter code and click the Finish button in the dialog box that appears, as shown in figure A.9.

Figure A.9. Locating the pom file

Eclipse will attempt to find connectors for the Gmaven-plus plugin and will fail because this plugin is fairly new (see figure A.10). Choose to ignore this (it won’t affect your build in any way). When you work with cutting-edge technology like Spock, your IDE can’t keep up with you!

Figure A.10. Ignoring Eclipse warnings

Next, make sure that the src/test/groovy directory is handled as a source directory, as shown in figure A.11:

Figure A.11. Ensuring that Eclipse handles src/test/groovy correctly

  • Right-click the project in Eclipse and select Properties (the last item on the menu). In the dialog box that appears, click Java Build Path.
  • Click the Add Folder button.
  • If the test/groovy directory isn’t already included, check it yourself.

To build the project, you can run mvn test from the command line. Alternatively, in Eclipse, you can choose “Maven test” from the project right-click menu, as shown in figure A.12.

Figure A.12. Running the Maven build

Then you can individually run any Spock test exactly as you would run a JUnit test (by right-clicking it), as shown in figure A.13.

Figure A.13. Running a Spock test in Eclipse

The results of the test appear in the JUnit console, as shown in figure A.14.

Figure A.14. Results of a Spock test

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.98.207