Skip to content

abhi2666/Python-Django-Test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing of Python-django app as a docker container inside Jenkins

Steps Followed

  1. Created a basic python-django app that sends a simply http response - "hello world"

Screenshot (399)

  1. Created a test case to check if the http response is "hello world" or not. Created a Dockerfile that will be later used by docker to create the image.

Screenshot (400)

  1. Pushed the code to the github so that jenkins can pull it.

  2. Created a Jenkins Pipeline to pull the code from git hub, then build the code and then test the code and generate test result file. (NO Jenkins file is created..pipeline is directly created inside the jenkins using pipeline script.)

Pipeline Script

pipeline { agent any

environment {
    DOCKER_IMAGE = "my-test-app"
}

stages {
    stage('Checkout') {
        steps {
            git branch: 'master', url: 'https://github.com/abhi2666/Python-Django-Test.git'
            echo "done collecting the repo !!"
        }
        
    }
    
    stage('Build Docker Image') {
        steps {
            script {
                sh 'docker build -t my-test-app .'
            }
            echo "Building docker image..."
            sh 'docker --version'
        }
    }
    
    // not recommended to run django development server directly on pipeline
    // better to test them directly.
    // stage('build') {
    //     steps {
    //         sh 'python3 --version'
    //         sh 'python3 manage.py runserver'
    //     }
    // }
    stage('Run Tests') {
        steps {
            sh 'pytest --junitxml=test-results.xml'
        }
    }

    
    
    stage('Report Test Results') {
        steps {
            junit 'test-results.xml'
        }
    }
}

post {
    always {
        cleanWs()
    }
}

}

  1. Below is the Jenkins console output.

Screenshot (401)

Screenshot (402)

Screenshot (403)

  1. Test report of the Django app.

Screenshot (404)

  1. Test cases passed Successfully.

About

Test repo to use jenkins and docker to automate testing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published