Simple Calculator Project

Module Objectives

  • Creating a simple project

  • Adding code

  • Uploading our code to GitLab

  • Writing test cases to check for failed and successful builds

Creating a Project Repository

Now that we have everything set up, we can start making projects. Start by logging into your normal user (if you haven't already), then go to Projects -> New Project. You can remove the README.

Set your project to public or private - we can use private for this one since we have our SSH key uploaded

Once it's been created, git clone your project into a directory

Cloning the project to our Windows host

Making a simple calculator

To test if our runner works, we will create a simple program which we can upload then run tests and configure pipelines for.

Let's make a simple calculator. I'll be using Go for this example

Test this by running go run calculator.go

Now that it works, we can push our demo app to our repository

Post-Push Repository

Writing Test Cases

Now that we have a functioning program, we can write a test case to check whether the values are acceptable, if not it will fail the build. We will reuse the code above for this

Reference

To run the test:

We can test for failure as well by changing the want variable to a random integer/string

Change back the values and push the code to your repository

Last updated

Was this helpful?