This is an example project to showcase how to organize application code, implement unit tests and define integrity tests using a BDT framework. The app is available under taschenrechner.sarumaj.com.
- handle invalid input
- complete open brackets
- abort incomplete arithmetic operations
- prevent invalid input (partially tested)
- in case of unforeseen exception, display NaN
- memory cell
- store result in a memory cell
- retrieve and reuse last result
To setup similar project follow following steps:
- Create GitHub repository.
- Install git CLI and authenticate it.
- Clone your repository:
git clone https://github.com/[username]/[repository name] cd [repository name]
- Initialize new Go module:
go mod init github.com/[username]/[repository name]
, wheregithub.com/[username]/[repository name]
will be your module name. - Start coding. Additional libraries can ben added using
go get [module name]
. Usego mod tidy
if necessary. - Define unit tests and execute:
go test -v ./...
- Execute:
go run [program entrypoint file]
- Build:
go build [program entrypoint file]
- Utilize version control:
- Status check:
git status
- Pull:
git pull
- Stage and commit:
git add . git commit -m "[your commit message goes here]"
- Push:
git push
- Advanced usage:
- Create a temporary branch:
git checkout -b [branch name]
- Pull, stage, commit
- Push:
git push --set-upstream origin [branch name]
- Create pull request and merge it through the web interface (github.com)
- Create a temporary branch:
- Status check:
- entrypoint main.go
- test suite for entrypoint main_test.go
- module file go.mod
- package pkg
- directory go-test
The application entrypoint makes use of the package ui. The import path is always the module name followed by the package path, e.g.
Property | Value |
---|---|
Module name | github.com/sarumaj/taschenrechner |
Package | pkg/ui |
Import path | github.com/sarumaj/taschenrechner/pkg/ui |
The app utilizes following frameworks:
As for the BDT testing the Cucumber framework and its Go implementation (Godog) are being used.
The unit test file sequence_test.go provides an example on how to write context-aware and well documented unit tests.
The unit test file cursor_test.go, unit test file parse_test.go, or unit test file tokens_test.go provide examples on how to write context-aware and compact unit tests (reduced number of lines).
The test suite for entrypoint main_test.go defines the feature steps parsed by the test engine:
^I press following buttons: "([^"]*)"$
^I get following result: "([^"]*)"$
The BDT feature file example.feature defines few test scenarios making use of the aforementioned feature steps.
Analyze this project and answer following questions:
- Testing
- How do the unit tests work?
- What advantages does BDT bring about? How is BDT set up for this project?
- How to increase test coverage, without increasing maintenance effort and code complexity?
- Data Models
- What are linked lists or trees? How is a linked tree used for parsing in this project?
- What are interfaces and what are they good for? How are they used in this project?
- Where do we use generics?
- Design Patterns and Coding Style
- Find and explain: Return Early Pattern.
- Find and explain: Method Chaining.
- Find and explain: Object Abstraction and Object Oriented Programming (OOP).
- Find and explain: Dependency/Configuration Injection.
- Logic
- How does the lexical parser work? What does a tokenizer do?
- What does the cursor do? How does it work?
- What is the memory cell for? How does it work?
- UI and Deployment
- Hos is the UI set up?
- How to compile the project?
- Documentation
- How to document a function? A custom type?
- How to publish code documentation?