GitHub Actions for Katalon
Certainly! You can use GitHub Actions to automate the execution of your unit tests whenever a push event occurs. Here's an example workflow that you can add to your GitHub repository to achieve this:
Create a new file in your GitHub repository at the following location:
.github/workflows/unit-tests.yml
.Open the newly created file and add the following content:
yamlname: Run Unit Tests
on:
push:
branches:
- master # Adjust this branch name if needed
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: '11' # Adjust the Java version as per your project's requirements
- name: Build project
run: ./gradlew assemble # Adjust the build command as per your project's requirements
- name: Run unit tests
run: ./gradlew test # Adjust the test command as per your project's requirements
- Save the file.
This workflow is triggered on a push event to the master
branch. It checks out the repository, sets up the Java environment, builds the project using ./gradlew assemble
, and finally runs the unit tests using ./gradlew test
. You can modify the build and test commands based on your specific project setup.
Commit and push this workflow file to your repository, and the GitHub Actions workflow will be activated. Now, whenever you push changes to the master
branch, the unit tests will automatically run.
Make sure your Katalon Studio project is set up to work with Gradle build system and has the necessary Gradle tasks defined for building and running the unit tests.
To configure your Gradle build to point to the unit tests in your Katalon Studio project, you'll need to make some modifications to your Gradle files. Here's how you can do it:
Open the
build.gradle
file in the root directory of your Katalon Studio project.Add the following dependencies to the
dependencies
section:
groovydependencies { // Other dependencies testImplementation 'junit:junit:4.12' // Add this line }
This adds the JUnit dependency to your project, which is commonly used for unit testing in Java projects.
Create a new directory called
src/test/java
in the root directory of your project. This is where you'll store your unit test files.Move or create your unit test files into the
src/test/java
directory. Make sure they follow the correct package structure and naming conventions.Open the
settings.gradle
file in the root directory of your project (if it doesn't exist, create it).Add the following lines to the
settings.gradle
file:
groovysourceSets { test { java.srcDirs = ['src/test/java'] } }
This configuration tells Gradle to include the src/test/java
directory as a source directory for the test
source set.
- Save the changes to the Gradle files.
Now your Gradle build is configured to recognize the unit tests located in the src/test/java
directory. You can use the test
Gradle task to execute your unit tests.
To run the unit tests using Gradle, open a terminal or command prompt, navigate to your project's root directory, and run the following command:
shell./gradlew test
Gradle will execute the unit tests and provide the test results.
Additionally, if you want to generate test reports, you can add the following configuration to your build.gradle
file:
groovytest { reports { junitXml.enabled = true html.enabled = true } }
This configuration enables the generation of JUnit XML and HTML test reports, which can be helpful for analyzing the test results. The reports will be generated in the build/reports
directory after running the test
task.
Apologies for the confusion. If your unit tests are located in the Test Cases/Unit Tests
directory in your Katalon Studio project, you can modify the Gradle build configuration accordingly. Here's how:
Open the
build.gradle
file in the root directory of your Katalon Studio project.Add the following lines to the
sourceSets
block:
groovysourceSets { // Other source sets test { java { srcDir 'Test Cases/Unit Tests' } } }
This configuration tells Gradle to include the Test Cases/Unit Tests
directory as a source directory for the test
source set.
- Save the changes to the
build.gradle
file.
Now your Gradle build is configured to recognize the unit tests located in the Test Cases/Unit Tests
directory. You can use the test
Gradle task to execute your unit tests.
To run the unit tests using Gradle, open a terminal or command prompt, navigate to your project's root directory, and run the following command:
shell./gradlew test
Gradle will execute the unit tests located in the Test Cases/Unit Tests
directory and provide the test results.
Remember to adjust the package structure and naming conventions of your unit test files accordingly to match the new location.
No, it is possible to modify the Gradle build configuration to run only certain test cases located in the Test Cases/Unit Tests
directory. Gradle provides various options to filter and select specific tests to execute.
To run only certain test cases, you can use Gradle's test filtering mechanism. Here's an example of how you can modify the Gradle build to run specific test cases:
Open the
build.gradle
file in the root directory of your Katalon Studio project.Modify the
test
task as follows:
groovytest { useJUnitPlatform() // Add the following lines include '**/YourTestClass1.class' include '**/YourTestClass2.class' // Add additional lines for other test classes you want to include // Alternatively, you can use exclude to exclude specific test classes // exclude '**/TestClassName.class' }
Replace YourTestClass1
and YourTestClass2
with the actual names of your test classes. You can add multiple include
statements to specify multiple test classes to be executed.
- Save the changes to the
build.gradle
file.
Now, when you run the test
task using Gradle, only the specified test classes will be executed. The other test classes will be excluded.
To run the modified test configuration, open a terminal or command prompt, navigate to your project's root directory, and run the following command:
shell./gradlew test
Gradle will execute the specified test classes and provide the test results.
Note that in this approach, you're specifying the test classes directly by their names. Ensure that the test class names match the actual test classes in your Test Cases/Unit Tests
directory. Also, make sure to adjust the package structure of the test classes as necessary to match the directory structure.
To run only the specific test cases you mentioned, you can modify the Gradle build configuration in the build.gradle
file as follows:
groovytest { useJUnitPlatform() include '**/RateIncreaseExpectationsHandler/Write new expectations model.class' include '**/RateIncreasePracticeModelHandler/Outputted Excel File.class' include '**/PracticeProfileHandler.class' include '**/Spreadsheet File Backup/*.class' }
Make sure to adjust the package structure and test class names according to your project's structure.
Here, we use the include
directive to specify the exact test class files you want to run. The **
pattern matches any subdirectories, allowing us to include tests under nested directories. For example, **/RateIncreaseExpectationsHandler/Write new expectations model.class
will match the test class located at Test Cases/Unit Tests/Rate Increase Model Handlers/RateIncreaseExpectationsHandler/Write new expectations model.class
.
To exclude specific test classes instead, you can use the exclude
directive in a similar manner. For example:
groovytest { useJUnitPlatform() exclude '**/SomeTestClass.class' exclude '**/AnotherTestClass.class' // Add additional lines for other test classes you want to exclude }
Save the changes to the build.gradle
file, and when you run ./gradlew test
, only the specified test cases will be executed, while the excluded ones will be skipped.