Skip to content

Commit

Permalink
[setup] Workflow Setup for Unit Testing (#7)
Browse files Browse the repository at this point in the history
* [setup] Separate properties for unit tests defined

* Create build.yml

* Create unitTests.yml

* Modified unitTests.yml

* Merged workflows for build and tests

* Cached gradle dependencies

* Seggregated workflows

* Fixed unitTest workflow

* Configured trigger events for workflows
  • Loading branch information
Rishabh2804 authored Nov 11, 2023
1 parent f64b495 commit d3ca392
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Spring Boot Build

on:
pull_request:
branch_protection_rule:
branches: [ dev, main ]
workflow_call:
workflow_dispatch: # Manually run the workflow

jobs:
gradle-build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 20.0.1
uses: actions/setup-java@v1
with:
java-version: 20.0.1

- name: Cache Gradle dependencies
id: gradle-cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build --stacktrace
38 changes: 38 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Spring Boot Unit Tests

on:
pull_request:
branch_protection_rule:
branches: [ dev, main ]
workflow_dispatch: # Manually run the workflow

jobs:
unit-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 20.0.1
uses: actions/setup-java@v1
with:
java-version: 20.0.1

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Restore Gradle build caches
id: gradle-cache-restore
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Run Tests
id: run-tests
run: ./gradlew test --stacktrace
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ dependencies {
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
runtimeOnly("mysql:mysql-connector-java:8.0.33")

// H2 database
runtimeOnly("com.h2database:h2")

// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
implementation("org.hibernate:hibernate-core:6.2.9.Final")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package spring.practice.zentarea;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.context.*;
import org.springframework.test.context.*;

@SpringBootTest
@TestPropertySource(locations = "classpath:application.properties")
class ZenTareaApplicationTests {

@Test
Expand Down
13 changes: 13 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spring.datasource.url=jdbc:h2:mem:test;MODE=MySQL;
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=
spring.datasource.password=
# We add the MySQL Dialect so that it understands and generates the query based on MySQL
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.h2.console.enabled=true
spring.jpa.defer-datasource-initialization=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.format_sql=true
spring.sql.init.mode=always

0 comments on commit d3ca392

Please sign in to comment.