Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 10-minute-tutorial for Java #101

Merged
merged 18 commits into from
Jan 14, 2018
Merged

Add 10-minute-tutorial for Java #101

merged 18 commits into from
Jan 14, 2018

Conversation

mlvandijk
Copy link
Member

@mlvandijk mlvandijk commented Jan 6, 2018

Add a 10-minute-tutorial for Java, with Maven, JUnit and IntelliJ.

A preview is available on Netlify.

Note: This PR does not include tutorials on JavaScript & Ruby.
Those can be added once this is reviewed & merged.

- An IDE editor, for example [IntelliJ IDEA](https://www.jetbrains.com/idea/?fromMenu#chooseYourEdition) (which will be used in this
introduction)

- A Cucumber plugin for your IDE, for example [IntelliJ IDEA Cucumber for Java plugin](https://plugins.jetbrains.com/plugin/7212-cucumber-for-java) to go with IntelliJ IDEA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been fixed yet to work with cucumber-jvm 2?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It hasn't. I see now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention anything about that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IDE plugin is presumably optional? Maybe a link to working with Cucumber outside of the IDE?

Copy link
Member Author

@mlvandijk mlvandijk Jan 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, not sure the plugin is optional with IntelliJ: https://www.jetbrains.com/help/idea/cucumber.html so I'm going to leave it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eclipse one works great and is available in the marketplace, in case you want to mention it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Flaburgan IntelliJ works fine otherwise, maybe when adding a tutorial with Eclipse. Thanks!


- [Cucumber-JVM](https://github.com/cucumber/cucumber-jvm) (which we will add as a dependency to our project)

- [JUnit 4](http://junit.org/junit4/) (which we will also add as a dependency to our project)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So not needed to get started. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll remove them here :)

2. Select **Run 'Feature: tutorial'** from the context menu.

{{% note "Formatter error"%}}
If you are using Cucumber v2.0.0 or higher, when running the test for the first time you might get an error message that mentions `CucumberJvmSMFormatterUtil`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using Cucumber v2.0.0 or higher can be removed we are using 2.0.0. You've specified that in the tutorial.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Will update


{{% note "Specify glue location"%}}
You might need to tell Cucumber where to find your `StepDefinitions.java` file (i.e. the 'glue' between your Gherkin and your programming code).
If so, open your **Run Configurations** and add the name of your `<project>` directory in the **Glue** field.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You describe a problem but not what the symptoms are.

@mlvandijk
Copy link
Member Author

mlvandijk commented Jan 8, 2018

Discussed with @mpkorstanje - as IntelliJ currently not working properly with Cucumber v2.x; I'll update this tutorial to describe running with a Cucumber runner (and move the running from InteliJ to running page)

Copy link
Contributor

@plaindocs plaindocs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments throughout, but this is good stuff!

- An IDE editor, for example [IntelliJ IDEA](https://www.jetbrains.com/idea/?fromMenu#chooseYourEdition) (which will be used in this
introduction)

- A Cucumber plugin for your IDE, for example [IntelliJ IDEA Cucumber for Java plugin](https://plugins.jetbrains.com/plugin/7212-cucumber-for-java) to go with IntelliJ IDEA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IDE plugin is presumably optional? Maybe a link to working with Cucumber outside of the IDE?


3. Make sure that the Project SDK is selected (for instance, Java 1.8) and click **Next**

4. Specify a **GroupId** and **ArtifactId** for your project and click **Next**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we tell people what these are for? Or do we assume they already know because they are setting up a Java project?

Copy link
Member Author

@mlvandijk mlvandijk Jan 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ad 3. Unfortunately cannot test what happens exactly as I have Java set up, so cannot describe in detail here. But I've helped coworkers who did not... and you run into interesting problems (stuff not getting recognized mainly)
Ad 4. If you don't, you cannot create the project.

For this tutorial, I'm going to assume they know why OR will just follow the steps (I only mention 3 because I've seen this lead to problems). Let me know if you disagree!


# Specifying Expected Behaviour

We specify the expected behaviour by defining features and scenarios.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link these?


We need to create this directory, as it was not created for us. In IntelliJ:

1. Right click on the Test folder, select **New > Directory** and name this directory `resources`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably skip telling people how to create a dir, and just tell them how to mark it as Test Resources Root


2. Right click the folder and select **Mark directory as > Test Resources Root**.

3. You can add subdirectories as needed. Create a subdirectory for your project in `src/test/resources/`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this whole thing our project?

}


Process finished with exit code 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Myabe add a little explanation. here of the step implementations shown? Or just a bit of flow text that takes us into the next section.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Process finished with exit code 0
```

## Snippets for Missing Steps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing Snippets for Missing Steps?


To add them to a Java class in IntelliJ:

1. Navigate to the `src/test/java/<project>` folder and right-click it to display the context menu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably condense these steps as well

Once you have implemented all your step definitions (and the expected behaviour in your application!) and the test passes, the summary of your results should look something like this:

```
Tests run: 5, Failures: 0, Errors: 0, Skipped: 4, Time elapsed: 0.656 sec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are they skipped?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-paste error. thanks!

```

# Examples
If you prefer to get started with a working project, try the skeleton project [which is available from GitHub](https://github.com/cucumber/cucumber-java-skeleton).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd link "skeleton project" not "available on GitHub"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And by this stage, asking them if they prefer something else feels odd. Maybe "If you'd like to test out a working example, try...

@mlvandijk
Copy link
Member Author

Thanks @plaindocs for the excellent feedback. Think this is ready to (squash! and) merge now...

@plaindocs plaindocs merged commit eba923e into master Jan 14, 2018
@plaindocs plaindocs deleted the tutorial branch January 14, 2018 14:47
@mlvandijk
Copy link
Member Author

Thanks @plaindocs !

@plaindocs
Copy link
Contributor

My pleasure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants