This repository is structured to help you getting started with unit testing and integration testing with JUnit
Java
and Gradle
.
Unit testing is a testing technique using which individual modules of the program are tested to determine if there are any issues. We are going to be using JUnit, a unit testing framework for Java.
- Download Java 8 JDK. Make sure that it is for your Operating System!
- Make sure you have declared the
JAVA_HOME
environment variable to the directory where JDK was installed. - Fork the repository by clicking on the Fork icon at the top right corner of this page.
- Clone the repository to your local machine by running the following commands on git:
git clone https://github.com/[YOUR-USERNAME]/junit-get-started.git
- If you need help, refer Forking and Cloning in git.
- Set the present working directory in terminal (or cmd) to your project. (
cd \YOUR_PROJECT_DIRECTORY
). - Run
./gradlew test
on Linux/Unix orgradlew test
on Windows.
-
If the file is being denied to open, the use
chmod +x ./gradlew
(for Linux/Unix) or runcmd as admin
(for Windows). -
If the file is being denied to open, the use
chmod +x ./gradlew
(for Linux/Unix) or runcmd as admin
(for Windows).
Alternatively, if you are using an IDE like Intellij IDEA
- Import the Git repository into the IDE and allow Gradle.
- Right-click the src/test/ directory.
- Click
Run 'All Tests'
or simply use theCtrl-Shift-F10
keyboard shortcut.
- Add a new test class under src/test/java for the suite of test cases to be added.
- Add 5 JUnit test cases in that class, one for each: -assertTrue -assertFalse -assertEquals -and any other two variety.
- Do verify that the tests successfully builds.
- Create a pull request requesting to merge the commits on your fork to this repository.
- Write a very conscise but informative pull request message,explaining the test cases in your pull request! Remember to use your words wisely.
- There is not much content in main code (src/main/). Add your test code to (src/test/) only.
- Do not edit ApplicationTest.java! Create a new test class instead to avoid merge conflicts.
- Remember to add comments in your code so that the other person can know what the test module does.
- Class names should always be in PascalCase.
- This repository has Travis CI integration, verify that it builds successfully before submitting the task.