JUnit Tutorial
Introduction to Junit JUnit Set up JUnit Architecture JUnit Annotations JUnit Fixtures Junit Assertions Junit Categories @Test Annotation Parameters Verification of Exceptions Ignoring tests Time out in JUnit tests Parameterizing tests Test Suite TestWatcher TemporaryFolder ExternalResource Theories in JUnit JUnit Test Runners Execution order of JUnit tests Assumptions in JUnit JUnit and Hamcrest Matchers Running JUnit tests in parallel JUnit and Maven Integration JUnit and Gradle Integration Executing Selenium tests using JUnit test framework Method interceptor and usage JUnit in Intellij IDEA JUnit in Eclipsegradle integration in junit
If you use a gradle as a build management tool, JUnit can be used to run the tests in your project.JUnit configuration in build.gradle file
To use JUnit in your gradle project, you will have to configure your build.gradle file as shown below. Key things to note about gradle build file are given below.- includeTestsMatching – This is used to specify the pattern for the test method and class names. To run all tests, you can use *.* pattern
- includeCategories – This is used to include tests from specific category
- excludeCategories – This is used to exclude tests from specific category
group 'org.softpost'
version '1.0-SNAPSHOT'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
test {
maxParallelForks=3
useJUnit {
//includeCategories '*.*'
excludeCategories 'categories.CategoryY'
}
filter {
//include specific method in any of the tests
includeTestsMatching "*.*"
}
}
Running JUnit tests from command line
Below command is used to run all JUnit tests from the project.
gradle test
Below command is used to run all JUnit tests from the test classes SanityTests and SimpleTest.
test –tests categories.SanityTests –tests junit.SimpleTest
Below command is used to run specific JUnit test methods.
test –tests categories.SanityTests.testSanity1
Below command is used to run tests from classes with their names ending with SanityTests.
gradle test –tests *SanityTests
Web development and Automation testing
solutions delivered!!