├── Intro to Coding Dojo.pdf
├── images
├── first_dev_gym.jpg
├── xcode_new_project.png
├── xcode_select_template.png
└── xcode_new_project_options.png
├── swift.md
├── rust_cargotest.md
├── ruby_rspec.md
├── dart_test.md
├── csharp_xunit.md
├── kotlin_kotlintest.md
├── README.md
├── golang_gotest.md
├── fsharp_xunit.md
├── nodejs_typescript_jest.md
├── nodejs_jest.md
├── scala_scalatest.md
├── nodejs_cucumber.md
├── nodejs_mocha.md
├── elixir_exunit.md
├── python_pytest.md
├── java_junit.md
├── organizers_guide
└── README.md
└── c++_gtest.md
/Intro to Coding Dojo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JuniorDevSingapore/coding_dojo/HEAD/Intro to Coding Dojo.pdf
--------------------------------------------------------------------------------
/images/first_dev_gym.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JuniorDevSingapore/coding_dojo/HEAD/images/first_dev_gym.jpg
--------------------------------------------------------------------------------
/images/xcode_new_project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JuniorDevSingapore/coding_dojo/HEAD/images/xcode_new_project.png
--------------------------------------------------------------------------------
/images/xcode_select_template.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JuniorDevSingapore/coding_dojo/HEAD/images/xcode_select_template.png
--------------------------------------------------------------------------------
/images/xcode_new_project_options.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JuniorDevSingapore/coding_dojo/HEAD/images/xcode_new_project_options.png
--------------------------------------------------------------------------------
/swift.md:
--------------------------------------------------------------------------------
1 | # Swift
2 |
3 | *__Note__: This guide assumes you have the latest Xcode installed.*
4 |
5 | 1. Start a new project in Xcode
6 |
7 | 
8 |
9 | 2. Select the "Cocoa Touch Framework" as the template for the new project.
10 |
11 | 
12 |
13 | 3. Do add the project name / kata exercise name.
14 |
15 | 
16 |
17 | Select Swift as the language. Select "Include Unit Tests".
18 |
19 | 4. Save in an appropriate folder.
20 | 5. Select a simulator.
21 | 6. Press `⌘` + `U` to execute the unit test.
22 | 7. The test should run and pass.
23 | 8. Open the first `*Test.swift` file and remove the sample test functions: `setUp`, `tearDown`, `testExample` and `testPerformanceExample`.
24 | 9. Press `⌘` + `N` to create a new file. Select `Swift File`. Click "Next". Give the file a name.
25 | 11. Make sure the file is included in the `*Tests` target.
26 | 12. You can now write new tests.
--------------------------------------------------------------------------------
/rust_cargotest.md:
--------------------------------------------------------------------------------
1 | # Rust - Bootstrapping Cargo Test
2 |
3 | *__Note__: This guide assumes you have [Rust](https://www.rust-lang.org/tools/install) installed.*
4 |
5 | 1. Create a new project structure for the code.
6 |
7 | (*Assuming the project is named `new_kata`*)
8 |
9 | ```shell
10 | cargo new new_kata --lib
11 | cd new_kata
12 | mkdir tests
13 | ```
14 |
15 | 2. Inside the tests folder (`tests`), create a test file (`lib.rs`) with the following content:
16 | ```rust
17 | extern crate new_kata;
18 |
19 | #[test]
20 | fn one_plus_two_is_three() {
21 | assert_eq!(3, new_kata::add(1, 2));
22 | }
23 | ```
24 |
25 | 3. Inside the src folder (`src`), replace the content of the implementation file (`lib.rs`) with the following:
26 | ```rust
27 | pub fn add(x: i32, y: i32) -> i32 {
28 | x + y
29 | }
30 | ```
31 |
32 | 4. Run the test.
33 | ```shell
34 | cargo test
35 | ```
36 | You should see this section:
37 |
38 | ```shell
39 | running 1 test
40 | test one_plus_two_is_three ... ok
41 |
42 | test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
43 | ```
44 |
45 |
46 | Checkout the [Rust Book](https://doc.rust-lang.org/book/) to know more about the language.
--------------------------------------------------------------------------------
/ruby_rspec.md:
--------------------------------------------------------------------------------
1 | # Ruby - Bootstrapping RSpec Test Suite
2 |
3 | *__Note__: This guide assumes you have Ruby installed.*
4 |
5 | 1. Install Bundler
6 |
7 | ```
8 | gem install bundler
9 | ```
10 |
11 | 2. Create a new project folder for the code:
12 |
13 | (*Assuming project name is `new_kata`*)
14 |
15 | ```
16 | mkdir new_kata
17 | cd new_kata
18 | ```
19 |
20 | 3. In the new project folder, initialize the `Gemfile`
21 |
22 | ```
23 | bundle init
24 | ```
25 |
26 | 4. Install RSpec
27 |
28 | ```
29 | bundle add rspec --group "test"
30 | ```
31 |
32 | 5. Initialize an RSpec test suite
33 |
34 | ```
35 | bundle exec rspec --init
36 | ```
37 |
38 | 6. Create a test file (`spec/sum_spec.rb`) with the following content:
39 |
40 | ```ruby
41 | require 'spec_helper'
42 | require_relative '../sum'
43 |
44 | describe 'sum' do
45 | it 'adds 1 + 2 to equal 3' do
46 | expect(sum(1, 2)).to eq 3
47 | end
48 | end
49 | ```
50 |
51 | 7. Create `sum.rb` with the following content:
52 |
53 | ```ruby
54 | def sum(a, b)
55 | a + b
56 | end
57 | ```
58 |
59 | 8. Run the test
60 |
61 | ```
62 | bundle exec rspec
63 | ```
64 |
65 | You should see this:
66 |
67 | ```
68 | .
69 |
70 | Finished in 0.00456 seconds (files took 0.10443 seconds to load)
71 | 1 example, 0 failures
72 | ```
73 |
74 | 9. Read up more about the types of test matchers available in RSpec: [https://relishapp.com/rspec/rspec-expectations/v/3-8/docs](https://relishapp.com/rspec/rspec-expectations/v/3-8/docs)
--------------------------------------------------------------------------------
/dart_test.md:
--------------------------------------------------------------------------------
1 | # Dart - Bootstrapping Test
2 |
3 | *__Note__: This guide assumes you have [Dart SDK](https://dart.dev/get-dart) and [stagehand](https://github.com/dart-lang/stagehand) installed.*
4 |
5 | 1. Create a new project structure for the code.
6 |
7 | (*Assuming the project is named `new_kata`*)
8 |
9 | ```shell
10 | mkdir new_kata
11 | cd new_kata
12 | stagehand package-simple
13 | pub get
14 | ```
15 |
16 | 2. Modify the generated implementation file (`new_kata\test\new_kata_test.dart`) with the following content:
17 | ```dart
18 | import 'package:new_kata/new_kata.dart';
19 | import 'package:test/test.dart';
20 |
21 | void main() {
22 | group('Coding Dojo Test Suite', () {
23 | KataLib library;
24 |
25 | setUp(() {
26 | library = KataLib();
27 | });
28 |
29 | test('Simple Addition Test', () {
30 | expect(library.add(1, 2), 3);
31 | });
32 | });
33 | }
34 | ```
35 |
36 | 3. Modify the generated implementation file (`new_kata\lib\src\new_kata_base.dart`) with the following content:
37 | ```dart
38 | class KataLib {
39 | int add(int x, int y) => x + y;
40 | }
41 | ```
42 |
43 | 4. Run the test.
44 | ```shell
45 | pub run test
46 | ```
47 | You should see something like this:
48 |
49 | ```shell
50 | 00:04 +1: All tests passed!
51 | ```
52 |
53 | Checkout the [Dart Language Tour](https://dart.dev/guides/language/language-tour) to know more about the language.
--------------------------------------------------------------------------------
/csharp_xunit.md:
--------------------------------------------------------------------------------
1 | # C# - Bootstrapping xUnit
2 |
3 | *__Note__: This guide assumes you have [.NET Core](https://dotnet.microsoft.com/download/core) installed.*
4 |
5 | 1. Create a new project folder for the code.
6 |
7 | (*Assuming the project is named `new_kata`*)
8 |
9 | ```shell
10 | dotnet new xunit -o new_kata
11 | cd new_kata
12 | rm .\UnitTest1.cs
13 | ```
14 |
15 | 2. Inside the project folder (`new_kata`), create a test file (`TestArithmetic.cs`) with the following content:
16 | ```csharp
17 | using System;
18 | using Xunit;
19 |
20 | namespace new_kata
21 | {
22 | public class TestArithmetic
23 | {
24 | [Fact]
25 | public void TestThat1Plus2Is3()
26 | {
27 | Assert.Equal(3, Arithmetic.Add(1, 2));
28 | }
29 | }
30 | }
31 | ```
32 |
33 | 3. Inside the project folder (`new_kata`), create the implementation file (`Arithmetic.cs`) with the following content:
34 | ```csharp
35 | namespace new_kata
36 | {
37 | public static class Arithmetic
38 | {
39 | public static int Add(int x, int y) => x + y;
40 | }
41 | }
42 | ```
43 |
44 | 4. Run the test.
45 | ```shell
46 | dotnet test
47 | ```
48 | You should see this:
49 |
50 | ```shell
51 | Starting test execution, please wait...
52 |
53 | Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
54 | Test Run Successful.
55 | ```
56 |
57 |
58 | Checkout the [C# Guide](https://docs.microsoft.com/en-us/dotnet/csharp/) to know more about the language.
--------------------------------------------------------------------------------
/kotlin_kotlintest.md:
--------------------------------------------------------------------------------
1 | # Kotlin - Bootstrapping Kotlin Test
2 |
3 | *__Note__: This guide assumes you have [JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html) and [Gradle](https://gradle.org/) installed.*
4 |
5 | 1. Create a new project structure for the code.
6 | When prompted, use the **default** values for *Project name* and *Source package*.
7 |
8 | (*Assuming the project is named `new_kata`*)
9 |
10 | ```shell
11 | mkdir new_kata
12 | cd new_kata
13 | gradle init --type kotlin-library --dsl kotlin
14 | ```
15 |
16 | 2. Modify the generated test file (`new_kata\src\test\kotlin\new_kata\LibraryTest.kt`) with the following content:
17 | ```kotlin
18 | package new_kata
19 |
20 | import kotlin.test.Test
21 | import kotlin.test.assertEquals
22 |
23 | class LibraryTest {
24 | @Test
25 | fun testSomeLibraryMethod() {
26 | val classUnderTest = Library()
27 | assertEquals(classUnderTest.Add(1, 2), 3)
28 | }
29 | }
30 | ```
31 |
32 | 2. Modify the generated implementation file (`new_kata\src\main\kotlin\new_kata\Library.kt`) with the following content:
33 | ```kotlin
34 | package new_kata
35 |
36 | class Library {
37 | fun Add(x: Int, y: Int): Int = x + y;
38 | }
39 | ```
40 |
41 | 4. Run the test.
42 | ```shell
43 | gradle test
44 | ```
45 | You should see this:
46 |
47 | ```shell
48 | BUILD SUCCESSFUL in 3s
49 | 3 actionable tasks: 3 up-to-date
50 | ```
51 |
52 |
53 | Checkout the [Kotlin Reference](https://kotlinlang.org/docs/reference/) to know more about the language.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Coding Dojo - Getting Started
2 |
3 | 
4 |
5 | This is meant to be a guide for participants involved in JuniorDevSG Coding Dojos.
6 |
7 | Here's a [quick intro to the Coding Dojo](https://docs.google.com/presentation/d/1c7jKltjGG8nK3r7iwODpC6qbZ4MxN1Iwd_e4zxgG1NY/edit?usp=sharing).
8 |
9 | ## Code Kata Bootstrap Guide
10 |
11 | Get started with your test environment in various programming languages.
12 |
13 | - [C# with xUnit](./csharp_xunit.md)
14 | - [C++ with Googletest](./c++_gtest.md)
15 | - [Dart with Test](./dart_test.md)
16 | - [F# with xUnit](./fsharp_xunit.md)
17 | - [Go with Go Test](./golang_gotest.md)
18 | - [Java with Junit, Gradle](./java_junit.md)
19 | - [Kotlin with Kotlin Test, Gradle](./kotlin_kotlintest.md)
20 | - [NodeJS with Jest](./nodejs_jest.md)
21 | - [NodeJS/TypeScript with Jest](./nodejs_typescript_jest.md)
22 | - [NodeJS with Mocha & Chai](./nodejs_mocha.md)
23 | - [NodeJS with Cucumber](./nodejs_cucumber.md)
24 | - [Python with pytest](./python_pytest.md)
25 | - [Ruby with RSpec](./ruby_rspec.md)
26 | - [Rust with Cargo Test](./rust_cargotest.md)
27 | - [Scala with ScalaTest](./scala_scalatest.md)
28 | - [Swift](./swift.md)
29 |
30 | ## Contributors
31 |
32 | - Gordon Song ([songguoqiang](https://github.com/songguoqiang))
33 | - Michael Cheng ([miccheng](https://github.com/miccheng))
34 | - Isha Tripathi ([isha-tripathi](https://github.com/isha-tripathi))
35 | - Björn Andersson ([gaqzi](https://github.com/gaqzi))
36 | - Paul Lorett Amazona ([whatevergeek](https://github.com/whatevergeek))
37 | - YING Ka Ho ([yingkh](https://github.com/yingkh))
38 | - William Haw ([williamhaw](https://github.com/williamhaw))
39 | - Dheeraj Oswal ([oswal-dheeraj](https://github.com/oswal-dheeraj))
40 |
--------------------------------------------------------------------------------
/golang_gotest.md:
--------------------------------------------------------------------------------
1 | # Go Lang - Bootstrapping Go Test
2 |
3 | *__Note__: This guide assumes you have Go installed and your `$GOPATH` is set.*
4 |
5 | 1. Create a new package in your `$GOPATH`:
6 |
7 | ```
8 | mkdir -p $GOPATH/src/code.in.spdigital.io/sp-digital/code_kata
9 | cd $GOPATH/src/code.in.spdigital.io/sp-digital/code_kata
10 | ```
11 |
12 | 2. Create a new file `main.go` file with the following contents:
13 |
14 | ```go
15 | package main
16 |
17 | func Sum(x, y int) int {
18 | return x + y
19 | }
20 |
21 | func main() {
22 | Sum(5, 5)
23 | }
24 | ```
25 |
26 | 3. Create a `main_test.go` test file with the following content:
27 |
28 | ```go
29 | package main
30 |
31 | import "testing"
32 |
33 | func TestSum(t *testing.T) {
34 | total := Sum(5, 5)
35 | if total != 10 {
36 | t.Errorf("Sum was incorrect, got: %d, want: %d.", total, 10)
37 | }
38 | }
39 | ```
40 |
41 | *__Note:__ Use `t.Error` or `t.Fail` to indicate a failure.*
42 |
43 | Here's an alternative with [table driven test][go-table-driven-test]:
44 |
45 | ```go
46 | package main
47 |
48 | import "testing"
49 |
50 | var cases = []struct{
51 | x int
52 | y int
53 | result int
54 | }{
55 | { 5, 5, 10 },
56 | { 8, 5, 13 },
57 | }
58 |
59 | func TestSum(t *testing.T) {
60 | for _, testCase := range cases {
61 | total := Sum(testCase.x, testCase.y)
62 | if total != testCase.result {
63 | t.Errorf("Sum was incorrect, got: %d, want: %d.", total, testCase.result)
64 | }
65 | }
66 | }
67 | ```
68 |
69 | 4. Run the test.
70 |
71 | ```
72 | go test
73 | ```
74 |
75 | You should see this:
76 |
77 | ```
78 | PASS
79 | ok code.in.spdigital.io/sp-digital/code_kata 0.008s
80 | ```
81 |
82 | [go-table-driven-test]: https://github.com/golang/go/wiki/TableDrivenTests
--------------------------------------------------------------------------------
/fsharp_xunit.md:
--------------------------------------------------------------------------------
1 | # F# - Bootstrapping xUnit
2 |
3 | *__Note__: This guide assumes you have [.NET Core](https://dotnet.microsoft.com/download/core) installed.*
4 |
5 | 1. Create a new project folder for the code.
6 |
7 | (*Assuming the project is named `new_kata`*)
8 |
9 | ```shell
10 | dotnet new xunit -o new_kata -lang F#
11 | cd new_kata
12 | dotnet add package FsUnit.xUnit
13 | ```
14 | 2. Delete the following files:
15 | ```
16 | Program.fs
17 | Tests.fs
18 | ```
19 | 3. Open the project file (`new_kata.fsproj`) in a text editor and replace the ItemGroup section with the following:
20 | ```xml
21 |
22 |
23 |
24 |
25 | ```
26 |
27 | 4. Inside the project folder (`new_kata`), create a test file (`ArithmeticTests.fs`) with the following content:
28 | ```fsharp
29 | module ArithmeticTests
30 |
31 | open FsUnit.Xunit
32 | open Xunit
33 |
34 | open Arithmetic
35 |
36 | []
37 | let ``Test that 1 + 2 is 3`` () =
38 | Add(1, 2) |> should equal 3
39 | ```
40 |
41 | 5. Inside the project folder (`new_kata`), create the implementation file (`Arithmetic.fs`) with the following content:
42 | ```fsharp
43 | module Arithmetic
44 |
45 | let Add(x: int, y: int): int = x + y
46 | ```
47 |
48 | 6. Run the test.
49 | ```shell
50 | dotnet test
51 | ```
52 | You should see this:
53 |
54 | ```shell
55 | Starting test execution, please wait...
56 |
57 | Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
58 | Test Run Successful.
59 | ```
60 |
61 |
62 | Checkout the [F# Guide](https://docs.microsoft.com/en-us/dotnet/fsharp/) to know more about the language.
--------------------------------------------------------------------------------
/nodejs_typescript_jest.md:
--------------------------------------------------------------------------------
1 | # NodeJS TypeScript - Bootstrapping Jest Test Suite
2 |
3 | Here's instructions on installing Jest and bootstrapping for TypeScript for Node.
4 |
5 | *__Note__: This guide assumes you have NodeJS installed.*
6 |
7 | 1. Create a new project folder for the code:
8 |
9 | (*Assuming project name is `new_kata`*)
10 |
11 | ```bash
12 | mkdir new_kata
13 | cd new_kata
14 | ```
15 |
16 | 2. In the new project folder, create `package.json`
17 |
18 | ```bash
19 | npm init -y
20 | ```
21 |
22 | 3. Add packages
23 |
24 | ```bash
25 | npm install typescript
26 | npm install --save-dev @types/node ts-node jest ts-jest @types/jest
27 | ```
28 |
29 | 4. Add test running script in `package.json`
30 |
31 | ```json
32 | "scripts": {
33 | "test": "jest",
34 | "test:watch": "jest --watch"
35 | }
36 | ```
37 |
38 | 5. Create a `ts-jest` config file:
39 |
40 | ```bash
41 | ./node_modules/.bin/ts-jest config:init
42 | ```
43 |
44 | 6. Create a `tsconfig.json` file:
45 |
46 | ```bash
47 | ./node_modules/.bin/tsc --init
48 | ```
49 |
50 | 7. Create a code (`sum.ts`) file
51 |
52 | ```typescript
53 | function sum(a: number, b: number): number {
54 | return a + b;
55 | }
56 | export default sum;
57 | ```
58 |
59 | 8. Create a test (`sum.test.ts`) file
60 |
61 | ```typescript
62 | import sum from './sum';
63 |
64 | describe('sum module', () => {
65 | test('adds 1 + 2 to equal 3', () => {
66 | expect(sum(1, 2)).toBe(3);
67 | });
68 | });
69 | ```
70 |
71 | 9. You can run the test:
72 |
73 | ```bash
74 | npm test
75 | ```
76 |
77 | You should see this:
78 |
79 | ```bash
80 | ➜ npm run test
81 |
82 | > demo@1.0.0 test
83 | > jest
84 |
85 | PASS src/sum.test.ts
86 | sum module
87 | ✓ adds 1 + 2 to equal 3 (1 ms)
88 |
89 | Test Suites: 1 passed, 1 total
90 | Tests: 1 passed, 1 total
91 | Snapshots: 0 total
92 | Time: 1.788 s
93 | Ran all test suites.
94 | ```
95 |
96 | 10. Read up more about the types of test matchers available in Jest:
97 |
--------------------------------------------------------------------------------
/nodejs_jest.md:
--------------------------------------------------------------------------------
1 | # NodeJS - Bootstrapping Jest Test Suite
2 |
3 | Here's instructions on installing Jest and bootstrapping for [ES6 module compilation][babel] for Node.
4 |
5 | *__Note__: This guide assumes you have NodeJS installed.*
6 |
7 | 1. Create a new project folder for the code:
8 |
9 | (*Assuming project name is `new_kata`*)
10 |
11 | ```bash
12 | mkdir new_kata
13 | cd new_kata
14 | ```
15 |
16 | 2. In the new project folder, create `package.json`
17 |
18 | ```bash
19 | yarn init
20 | ```
21 |
22 | or
23 |
24 | ```bash
25 | npm init
26 | ```
27 |
28 | 3. Add packages
29 |
30 | ```bash
31 | yarn add --dev jest @babel/core @babel/preset-env
32 | ```
33 |
34 | or
35 |
36 | ```bash
37 | npm install --save-dev jest @babel/core @babel/preset-env
38 | ```
39 |
40 | 4. Add test running script in `package.json`
41 |
42 | ```json
43 | "scripts": {
44 | "test": "jest",
45 | "test:watch": "jest --watch"
46 | }
47 | ```
48 |
49 | 5. Create a `.babelrc` with these content for a [smart preset babel configuration][babel-preset-env]
50 |
51 | ```json
52 | {
53 | "presets": [
54 | ["@babel/preset-env",
55 | {
56 | "targets": {
57 | "node": "10"
58 | }
59 | }
60 | ]
61 | ]
62 | }
63 | ```
64 |
65 | 6. Create a code (`sum.js`) file
66 |
67 | ```javascript
68 | const sum = (a, b) => a + b
69 | export default sum
70 | ```
71 |
72 | 7. Create a test (`sum.test.js`) file
73 |
74 | ```javascript
75 | import sum from './sum'
76 |
77 | test('adds 1 + 2 to equal 3', () => {
78 | expect(sum(1, 2)).toBe(3);
79 | });
80 | ```
81 |
82 | 8. You can run the test:
83 |
84 | ```bash
85 | yarn test
86 | ```
87 |
88 | or
89 |
90 | ```bash
91 | npm test
92 | ```
93 |
94 | You should see this:
95 |
96 | ```bash
97 | yarn run v1.9.4
98 | $ jest
99 | PASS ./sum.test.js
100 | ✓ adds 1 + 2 to equal 3 (3ms)
101 |
102 | Test Suites: 1 passed, 1 total
103 | Tests: 1 passed, 1 total
104 | Snapshots: 0 total
105 | Time: 1.286s
106 | Ran all test suites.
107 | ✨ Done in 2.39s.
108 | ```
109 |
110 | 9. Read up more about the types of test matchers available in Jest: [https://jestjs.io/docs/en/using-matchers][jest-matchers]
111 |
112 | [babel]: https://babeljs.io/docs/en/
113 | [babel-preset-env]: https://babeljs.io/docs/en/babel-preset-env
114 | [jest-matchers]: https://jestjs.io/docs/en/using-matchers
115 |
--------------------------------------------------------------------------------
/scala_scalatest.md:
--------------------------------------------------------------------------------
1 | # Scala - Bootstrapping with ScalaTest
2 |
3 | Prerequisites: JDK - please download and install from [AdoptOpenJDK](https://adoptopenjdk.net)
4 |
5 | ## Steps
6 |
7 | 1. Install sbt:
8 |
9 | Mac:
10 | ```bash
11 | $ brew install sbt@1
12 | ```
13 |
14 | Windows:
15 | Install msi from [here](https://www.scala-sbt.org/release/docs/Installing-sbt-on-Windows.html)
16 |
17 | Linux:
18 | [Installation instructions](https://www.scala-sbt.org/release/docs/Installing-sbt-on-Linux.html)
19 |
20 | 2. Create new project from seed:
21 |
22 | ```bash
23 | $ sbt new sbt/scala-seed.g8
24 | ```
25 |
26 | After installing everything, you will be prompted for the project name:
27 |
28 | ```bash
29 | A minimal Scala project.
30 |
31 | name [Scala Seed Project]:
32 | ```
33 |
34 | Enter `kata` and then `cd kata`
35 |
36 | 3. You will find an example source file at `src/main/scala/example/Hello.scala` and an example test file at `src/test/scala/example/HelloSpec.scala`.
37 |
38 | 4. You may run the tests with:
39 |
40 | ```bash
41 | sbt test
42 | ```
43 |
44 | To have sbt watch the file system for changes(run tests on save), use
45 |
46 | ```bash
47 | sbt ~test:compile
48 | ```
49 |
50 | ## Explanation
51 |
52 | The seed is a template that can be found [here](https://github.com/scala/scala-seed.g8). It sets up a new sbt project with some sensible defaults.
53 |
54 | Structure of the project:
55 | ```
56 | ├── build.sbt // contains settings for the build, for e.g. Scala version, project version and project name
57 | ├── project // build support files
58 | │ └── Dependencies.scala // lists dependencies
59 | │ └── build.properties // defines sbt version
60 | ├── target // temporary folder for build output
61 | └── src
62 | ├── main
63 | │ └── scala // Scala code goes here
64 | └── test
65 | └── scala // Scala tests go here
66 | ```
67 |
68 | ## References
69 | - [Scala language guide](https://docs.scala-lang.org/tour/tour-of-scala.html)
70 | - [Scala for Java programmers](https://docs.scala-lang.org/tutorials/scala-for-java-programmers.html)
71 | - [sbt documentation](https://www.scala-sbt.org/release/docs/Getting-Started.html)
72 | - [ScalaTest documentation](http://www.scalatest.org/user_guide/writing_your_first_test)
73 | - [ScalaTest matchers](http://www.scalatest.org/user_guide/using_matchers)
--------------------------------------------------------------------------------
/nodejs_cucumber.md:
--------------------------------------------------------------------------------
1 | # NodeJS - Bootstrapping Cucumber
2 |
3 | > Cucumber is a tool that supports Behavior Driven Development (BDD).
4 |
5 | *__Note__: This guide assumes you have NodeJS installed.*
6 |
7 | 1. Create a new project directory
8 |
9 | ```bash
10 | mkdir new_kata
11 | ```
12 |
13 | 2. Create `package.json` inside the new project
14 |
15 | ```bash
16 | cd new_kata
17 | npm init -y
18 | ```
19 |
20 | 3. Add `cucumber` and `chai` packages
21 |
22 | ```bash
23 | npm install --save-dev cucumber chai
24 | ```
25 |
26 | *__Note__: We will use `chai` for making assertions.*
27 |
28 |
29 | 4. Add test running script in `package.json`
30 |
31 | ```json
32 | "scripts": {
33 | "test": "cucumber-js"
34 | }
35 | ```
36 |
37 | 5. Create a feature file inside `features` directory
38 |
39 | ```bash
40 | mkdir features
41 | touch features/Calc.feature
42 | ```
43 |
44 | ```gherkin
45 | Feature: Calculator
46 | As a budding developper
47 | I want to learn BDD
48 | So that there will be less misinterpretation of spec
49 |
50 | Scenario: A Simple calculator
51 | Given there is a calculator
52 | When we add 1 and 2
53 | Then the result should be 3
54 | ```
55 |
56 | 6. Generate step definitions.
57 |
58 | Running `npm test` should produce a warning about undefined steps and print the snippets for missing `Given`, `When` and `Then`. Copy them to `features/steps/CalcSteps.js` and change as follows:
59 |
60 | ```javascript
61 | const { Given, When, Then } = require('cucumber')
62 | const { expect } = require('chai')
63 | const { Calc } = require('../../src/Calc')
64 |
65 | let calc, result
66 |
67 | Given('There is a calculator', function () {
68 | calc = new Calc()
69 | })
70 |
71 | When('we add {int} and {int}', function (first, second) {
72 | result = calc.add(first, second)
73 | })
74 |
75 | Then('the result should be {int}', function (expected) {
76 | expect(result).to.equal(expected)
77 | })
78 | ```
79 |
80 | 7. Implement the calculator in `src/Calc.js`.
81 |
82 | ```javascript
83 | class Calc {
84 | add(a, b) {
85 | return a + b
86 | }
87 | }
88 |
89 | module.exports = { Calc }
90 | ```
91 |
92 | 8. Run the test
93 |
94 | ```bash
95 | npm test
96 | ```
97 |
98 | You should see this:
99 |
100 | ```bash
101 | > new_kata@1.0.0 test /YOUR-HOME/PATH-TO/new_kata
102 | > cucumber-js
103 |
104 | ...
105 |
106 | 1 scenario (1 passed)
107 | 3 steps (3 passed)
108 | 0m00.002s
109 | ```
110 |
111 | Your working directory should look like:
112 |
113 | ```text
114 | $ tree
115 | .
116 | |____src/
117 | | |____Calc.js
118 | |____features/
119 | | |____Calc.feature
120 | | |____steps/
121 | | | |____CalcSteps.js
122 | |____package.json
123 | |____package-lock.json
124 | ```
125 |
126 | 9. References
127 |
128 | * [Cucumber](https://cucumber.io/docs/guides/)
129 | * [Chai](https://www.chaijs.com/)
130 |
--------------------------------------------------------------------------------
/nodejs_mocha.md:
--------------------------------------------------------------------------------
1 | # NodeJS - Bootstrapping Mocha Test Suite
2 |
3 | Here's instructions on installing Mocha and Chai for Node.
4 |
5 | *__Note__: This guide assumes you have NodeJS installed.*
6 |
7 | > Mocha is an alternative test framework used in javascript.
8 | > Chai is an assertion library that is used along with Mocha.
9 |
10 | 1. Create a new project folder for the code:
11 |
12 | (*Assuming project name is `new_kata`*)
13 |
14 | ```bash
15 | mkdir new_kata
16 | cd new_kata
17 | ```
18 |
19 | 2. In the new project folder, create `package.json`
20 |
21 | ```bash
22 | yarn init
23 | ```
24 |
25 | or
26 |
27 | ```bash
28 | npm init
29 | ```
30 |
31 | 3. Add packages
32 |
33 | ```bash
34 | yarn add --dev mocha chai @babel/core @babel/preset-env @babel/register
35 | ```
36 |
37 | or
38 |
39 | ```bash
40 | npm install --save-dev mocha chai @babel/core @babel/preset-env @babel/register
41 | ```
42 |
43 | 4. Add test running script in `package.json`
44 |
45 | ```json
46 | "scripts": {
47 | "test": "mocha --require @babel/register",
48 | "test:watch": "mocha --require @babel/register --watch"
49 | }
50 | ```
51 |
52 | 5. Create a `.babelrc` with these content for a [smart preset babel configuration][babel-preset-env]
53 |
54 | ```json
55 | {
56 | "presets": [
57 | ["@babel/preset-env",
58 | {
59 | "targets": {
60 | "node": "10"
61 | }
62 | }
63 | ]
64 | ]
65 | }
66 | ```
67 |
68 | 6. Create two directories, src and test
69 |
70 | ```bash
71 | mkdir src
72 | mkdir test
73 | ```
74 |
75 | 7. Create a code (`sum.js`) file and store in `src` directory
76 |
77 | ```javascript
78 | const sum = (a, b) => a + b
79 | export default sum
80 | ```
81 |
82 | 8. Create a test (`sum.test.js`) file and store in `test` directory.
83 |
84 | ```javascript
85 | import { expect } from 'chai'
86 | import sum from '../src/sum'
87 |
88 | it( '1 + 2 should be 3', function() {
89 | expect( sum( 1, 2 ) ).to.equal( 3 )
90 | } )
91 | ```
92 | > For mocha, it's important that the test scripts are stored in the test directory becuase
93 | > the mocha test runner will look for test script in the test directory.
94 |
95 | 9. You can run the test:
96 |
97 | ```bash
98 | yarn test
99 | ```
100 |
101 | or
102 |
103 | ```bash
104 | npm test
105 | ```
106 |
107 | You should see this:
108 |
109 | ```bash
110 | $ mocha
111 |
112 | ✓ 1 + 2 should be 3
113 |
114 | 1 passing (5ms)
115 | ```
116 |
117 | 10. Read up more about this set of test frameworks:
118 |
119 | * For test framework: [Mocha](https://mochajs.org/)
120 | * For assertion framework: [Chai](https://www.chaijs.com/)
121 | * For mocking framework: [Sinon](https://sinonjs.org/)
122 |
123 | _Reference: [My Node.js Setup (Mocha & Chai, Babel7, ES6)](https://dev.to/bnorbertjs/my-nodejs-setup-mocha--chai-babel7-es6-43ei)_
124 |
125 | [babel-preset-env]: https://babeljs.io/docs/en/babel-preset-env
--------------------------------------------------------------------------------
/elixir_exunit.md:
--------------------------------------------------------------------------------
1 | # Elixir - Bootstrapping ExUnit
2 |
3 | *__Note__: This guide assumes you have Elixir installed.*
4 |
5 | 1. Create a new mix project:
6 |
7 | (*Assuming the project is named `new_kata`*)
8 |
9 | ```shell
10 | mix new new_kata
11 | cd new_kata
12 | ```
13 |
14 | 2. ExUnit comes built into Elixir, so no additional installation is needed. It's automatically configured in `test/test_helper.exs`:
15 |
16 | ```elixir
17 | ExUnit.start()
18 |
19 | ```
20 |
21 | Test files are usually placed in the `test` directory, and are named like `*_test.exs`. Mix should also have created a `test/new_kata_test.exs` file with the following content:
22 |
23 | ```elixir
24 | defmodule NewKataTest do
25 | use ExUnit.Case
26 | doctest NewKata
27 |
28 | test "greets the world" do
29 | assert NewKata.hello() == :world
30 | end
31 | end
32 | ```
33 |
34 | We can run this test with `mix test`.
35 |
36 | ```shell
37 | ..
38 | Finished in 0.01 seconds (0.00s async, 0.01s sync)
39 | 1 doctest, 1 test, 0 failures
40 | ```
41 |
42 | 3. Create a new test file (`test/arithmetic_test.exs`) with the following content:
43 |
44 | ```elixir
45 | defmodule ArithmeticTest do
46 | use ExUnit.Case
47 | doctest Arithmetic
48 |
49 | test "sum of two numbers" do
50 | assert Arithmetic.sum(1, 2) == 3
51 | end
52 | end
53 | ```
54 |
55 | 4. Create `lib/arithmetic.ex` with the following content:
56 |
57 | ```elixir
58 | defmodule Arithmetic do
59 | @moduledoc """
60 | A module for performing arithmetic operations.
61 | """
62 |
63 | @doc """
64 | Sum two numbers.
65 |
66 | ## Examples
67 |
68 | iex> Arithmetic.sum(1, 2)
69 | 3
70 | """
71 | def sum(a, b) do
72 | a + b
73 | end
74 | end
75 | ```
76 |
77 | 5. Run the test:
78 |
79 | ```shell
80 | mix test
81 | ```
82 |
83 | You should see this:
84 |
85 | ```shell
86 | ...
87 | Finished in 0.00 seconds (0.00s async, 0.00s sync)
88 | 2 doctest, 2 tests, 0 failures
89 | ```
90 |
91 | ## About ExUnit
92 |
93 | ExUnit is Elixir's built-in test framework that comes with a rich set of assertions and great test organization features. Here's an example showing some of ExUnit's helpful error messages:
94 |
95 | ```elixir
96 | test "demonstrates helpful error messages" do
97 | assert [1, 2, 3] == [1, 2, 3, 4]
98 | end
99 | ```
100 |
101 | This will give you the following output:
102 |
103 | ```shell
104 | 1) test demonstrates helpful error messages (ArithmeticTest)
105 | test/arithmetic_test.exs:9
106 | Assertion with == failed
107 | code: assert [1, 2, 3] == [1, 2, 3, 4]
108 | left: [1, 2, 3]
109 | right: [1, 2, 3, 4]
110 | stacktrace:
111 | test/arithmetic_test.exs:10: (test)
112 | ```
113 |
114 | ExUnit provides many useful assertions:
115 | - `assert` - verifies that a condition is truthy
116 | - `refute` - verifies that a condition is falsy
117 | - `assert_raise` - verifies that code raises an error
118 | - `assert_receive` - verifies that a message was received (useful for testing processes)
119 |
--------------------------------------------------------------------------------
/python_pytest.md:
--------------------------------------------------------------------------------
1 | # Python - Bootstrapping pytest Test Suite
2 |
3 | *__Note__: This guide assumes you have Python installed.*
4 |
5 | 1. Install [pipenv]
6 |
7 | ```shell
8 | pip install pipenv
9 | ```
10 |
11 | 2. Create a new project folder for the code:
12 |
13 | (*Assuming the project is named `new_kata`*)
14 |
15 | ```shell
16 | mkdir new_kata
17 | cd new_kata
18 | ```
19 |
20 | 3. In the new project folder, install pytest as a development dependency
21 |
22 | ```shell
23 | pipenv install --dev pytest
24 | ```
25 |
26 | 4. Create a test file (`test_sum.py`) with the following content:
27 |
28 | ```python
29 | from sum import sum
30 |
31 |
32 | class TestSum:
33 | def test_additions_are_additive(self):
34 | assert sum(1, 1) == 2, "expected two numbers to add up"
35 | ```
36 |
37 | 4. Create `sum.py` with the following content:
38 |
39 | ```python
40 | def sum(a, b):
41 | return a + b
42 | ```
43 |
44 | 5. Run the test:
45 |
46 | ```shell
47 | pipenv run pytest
48 | ```
49 |
50 | You should see this:
51 |
52 | ```shell
53 | === test session starts ===
54 | platform darwin -- Python 3.6.1, pytest-4.4.1, py-1.8.0, pluggy-0.11.0
55 | rootdir: /Users/ba/workspace/coding_dojo
56 | collected 1 item
57 |
58 | test_sum.py . [100%]
59 |
60 | === 1 passed in 0.02 seconds ===
61 | ```
62 |
63 | ## About pytest
64 |
65 | Pytest is a fairly magic library that extends Python's built-in `assert` to
66 | handle most types in a nice understandable way. For instance, if you ask it to
67 | compare two lists it'll happily tell you which of the two lists contains a
68 | differing item and where it is. For example:
69 |
70 | ```python
71 | def test_failing_lists(self):
72 | assert [1] == [1, 2]
73 | ```
74 |
75 | will give you the following output:
76 |
77 | ```shell
78 | === test session starts ===
79 | platform darwin -- Python 3.6.1, pytest-4.4.1, py-1.8.0, pluggy-0.11.0
80 | rootdir: /Users/ba/workspace/coding_dojo
81 | collected 2 items
82 |
83 | test_sum.py .F [100%]
84 |
85 | === FAILURES ===
86 | ___ TestSum.test_failing_lists ___
87 |
88 | self =
89 |
90 | def test_failing_lists(self):
91 | > assert [1] == [1, 2]
92 | E assert [1] == [1, 2]
93 | E Right contains more items, first extra item: 2
94 | E Use -v to get the full diff
95 |
96 | test_sum.py:9: AssertionError
97 | === 1 failed, 1 passed in 0.06 seconds ===
98 | ```
99 |
100 | ## About pipenv
101 |
102 | Pipenv is a tool for managing all your dependencies and helping you make sure
103 | the correct version of them is installed everywhere (it's similar to Ruby's
104 | `bundler`). It will under the hood create a [virtual environment
105 | (venv/virtualenv)] for you and keep all of your current project's dependencies
106 | separate from any other app. To learn more about pipenv check out the
107 | [website][pipenv].
108 |
109 | [pipenv]: https://pipenv.readthedocs.io/en/latest/
110 | [virtualenv]: https://virtualenv.pypa.io/en/stable/
111 |
--------------------------------------------------------------------------------
/java_junit.md:
--------------------------------------------------------------------------------
1 | # Java - Bootstrapping JUnit
2 |
3 | Here's instructions on bootstrapping a Java project with Gradle and JUnit4
4 |
5 | *__Note__: This guide assumes you have Java installed.*
6 |
7 | 1. Install gradle:
8 |
9 | with __Homebrew__:
10 | ```bash
11 | $ brew install gradle
12 | ```
13 |
14 | Manually:
15 | ```bash
16 | $ wget https://services.gradle.org/distributions/gradle-5.4.1-bin.zip
17 | $ sudo mkdir /opt/gradle
18 | $ sudo unzip -d /opt/gradle gradle-5.4.1-bin.zip
19 | $ export PATH=$PATH:/opt/gradle/gradle-5.4.1/bin
20 | ```
21 |
22 | Run the following your installation went through correctly
23 | ```bash
24 | $ gradle -v
25 | ```
26 |
27 | 2. Create a new project folder for the code:
28 | ```bash
29 | $ mkdir
30 | $ cd
31 | ```
32 |
33 | 3. Initialise the project as a Gradle project.
34 |
35 | This will create the necessary files and folders, along with a gradle wrapper
36 | ```bash
37 | $ gradle init
38 | ```
39 | Run the following to ensure everything is configured as expected:
40 | ```bash
41 | $ ./gradlew -v
42 | ```
43 | You should see the same result as above
44 |
45 | 4. Create the directories corresponding to the standard Java directory structure:
46 | ```bash
47 | $ mkdir src && cd src
48 | $ mkdir main
49 | $ mkdir test
50 | $ mkdir main/java
51 | $ mkdir test/java
52 | ```
53 | Your project structure should now look like:
54 | ```
55 | .
56 | ├── build.gradle
57 | ├── gradle
58 | │ └── wrapper
59 | │ ├── gradle-wrapper.jar
60 | │ └── gradle-wrapper.properties
61 | ├── gradlew
62 | ├── gradlew.bat
63 | ├── settings.gradle
64 | └── src
65 | ├── main
66 | │ └── java
67 | └── test
68 | └── java
69 | ```
70 | 5. Create a class under `src/main/java`. For example,
71 |
72 | *HelloWorld.java*
73 | ```java
74 | public class HelloWorld {
75 | public String say() {
76 | return "Hello, World!";
77 | }
78 | }
79 | ```
80 | 6. Create a corresponding test class under `src/main/test`.
81 |
82 | *HelloWorldTest.java*
83 | ```java
84 | import org.junit.Test;
85 | import org.junit.Assert;
86 |
87 | public class HelloWorldTest {
88 | @Test
89 | public void shouldSayHelloWorld() {
90 | HelloWorld helloWorld = new HelloWorld();
91 |
92 | Assert.assertEquals("Hello, World!", helloWorld.say());
93 | }
94 |
95 | }
96 | ```
97 | This does not compile just yet. To make it compile, you need to add JUnit as a dependency to your project.
98 |
99 | 7. Add JUnit to the project. Add the following content in your `build.gradle` file:
100 |
101 | ```groovy
102 | apply plugin: 'java'
103 |
104 | repositories {
105 | mavenCentral()
106 | }
107 |
108 | dependencies {
109 | testImplementation 'junit:junit:4.12'
110 | }
111 | ```
112 | 8. Run the build as follows:
113 | ```bash
114 | $ ./gradlew build
115 | ```
116 | You should see:
117 | ```bash
118 | BUILD SUCCESSFUL in 0s
119 | 4 actionable tasks: 4 up-to-date
120 | ```
121 |
122 | __You are all set now with your Java project__
--------------------------------------------------------------------------------
/organizers_guide/README.md:
--------------------------------------------------------------------------------
1 | # Organizers Guide
2 |
3 | ## Venue
4 |
5 | Criteria for venue:
6 |
7 | - Relatively quiet area.
8 | - Many tables for pair-programming.
9 | - Ample power supply / sockets or extensions.
10 | - Refreshments available (either from the host's pantry or readily available nearby)
11 | - Easily accessible.
12 |
13 | ## Suggested Program
14 |
15 | Time | Event
16 | :--- |:-----
17 | 10:00am | Intro to Coding Dojo / Code Kata / Pair Programming
18 | 10:15am | Reveal Code Kata for the day
19 | 10:30am | Pair up and attempt Code Kata (pairs can choose their own choice of programming language)
20 | 11:30am | Break
21 | 11:45pm | Continue Code Kata
22 | 12:30pm | Show and Tell
23 |
24 | ## Introduction
25 |
26 | You can use [these slides](https://docs.google.com/presentation/d/1c7jKltjGG8nK3r7iwODpC6qbZ4MxN1Iwd_e4zxgG1NY/edit?usp=sharing) to introduce the participants to the concepts of Coding Dojo, Code Kata, TDD and Pair Programming.
27 |
28 | ## Code Kata
29 |
30 | Here are some useful sites that we use to get the Code Kata:
31 |
32 | - [http://codingdojo.org/kata/](http://codingdojo.org/kata/)
33 | - [http://codekata.com/](http://codekata.com/)
34 | - [http://kata-log.rocks/](http://kata-log.rocks/)
35 |
36 | ## Pairing Up
37 |
38 | After revealing the Code Kata for the day, get the participants to pair up and go to their corners to start the challenge.
39 |
40 | Pairing can happen in various ways:
41 |
42 | - Find a pair who wants to use a specific language (either to level up or teach)
43 | - Random drawing
44 |
45 | For optimum experience, we should pair up an experienced coder with a less expereinced one. Experience in terms of understanding of a language or in doing Code Katas.
46 |
47 | ## Event Announcement Message (Meetup.com)
48 |
49 | ```
50 | Date: *Date here*
51 | Time: *Time here*
52 |
53 | ======================
54 | Do you know what a Coding Dojo is?
55 |
56 | > A Coding Dojo is a meeting where a bunch of coders get together to work on a programming challenge. They are there to have fun and to engage in Deliberate Practice in order to improve their skills.
57 |
58 | The *focus* of the Coding Dojo would be to help you improve your skills in the language you are working on (or ramping up on). We also hope that pair-programming with more experienced devs will help you level up.
59 |
60 | *Format* wise, the team will be given a Code Kata (a coding puzzle) where they have to solve by writing code. And through pair-programming, they will learn about writing test (TDD) and using advanced coding techniques from the more experienced devs in your group.
61 |
62 | ======================
63 | What is a Code Kata?
64 |
65 | A kata is an exercise in karate where you repeat a form many, many times, making little improvements in each.
66 |
67 | You need to try it as many times as it takes, and be comfortable making mistakes. You need to look for feedback each time so you can work to improve.
68 |
69 | Remember that the point of the kata is not arriving at a correct answer. The point is the stuff you learn along the way. The goal is the practice, not the solution.
70 |
71 | ======================
72 | Agenda:
73 |
74 | 10:00am - Intro to Coding Dojo / Code Kata / Pair Programming
75 | 10:15am - Reveal Code Kata for the day
76 | 10:30am - Pair up and attempt Code Kata (pairs can choose their own choice of programming language)
77 | 11:30am - Break
78 | 11:45pm - Continue Code Kata
79 | 12:30pm - Show and Tell
80 |
81 | ======================
82 | What do i need to bring?
83 |
84 | You will be coding - so bring your laptop and make sure you have all your coding tools and dev environment installed.
85 |
86 | I suggest bringing along your own keyboard and mouse so that you can connect to your pair-programming partner's laptop.
87 |
88 | =====================
89 | Venue Sponsor: *Name of sponsor*
90 | ```
91 |
--------------------------------------------------------------------------------
/c++_gtest.md:
--------------------------------------------------------------------------------
1 | # C++ - Bootstrapping Googletest
2 |
3 | *__Note__: This guide assumes you have a C++ compiler installed.*
4 |
5 | 1. Install [cmake]:
6 |
7 | - Mac
8 |
9 | ```shell
10 | $ brew install cmake
11 | ```
12 |
13 | - Linux
14 |
15 | ```shell
16 | $ DIR=`mktemp -d`
17 | $ cd $DIR
18 | $ wget https://github.com/Kitware/CMake/releases/download/v3.15.4/cmake-3.15.4-Linux-x86_64.sh
19 | $ sudo mkdir /opt/cmake
20 | $ sudo sh cmake-3.15.4-Linux-x86_64.sh --skip-license --exclude-subdir --prefix=/opt/cmake
21 | $ rm cmake-3.15.4-Linux-x86_64.sh
22 | ```
23 | *__Note__: CMake 3.15.4 is the latest version at the time of writing*
24 |
25 | Optionally add CMake to the PATH variable
26 | ```shell
27 | echo 'export PATH=/opt/cmake/bin:$PATH' >> ~/.bashrc
28 | ```
29 | Verify that the installation was successful
30 | ```shell
31 | cmake --version
32 | ```
33 |
34 | 2. Create a new project folder for the code:
35 |
36 | ```shell
37 | $ mkdir
38 | $ cd
39 | ```
40 |
41 | 3. Setup CMake to auto download [googletest]:
42 |
43 | Add a file called `AutoDownloadGTest.cmake` under `cmake/modules` with the below contents
44 | ```cmake
45 | include(FetchContent)
46 |
47 | FetchContent_Declare(
48 | googletest
49 | GIT_REPOSITORY https://github.com/google/googletest.git
50 | GIT_TAG release-1.10.0
51 | )
52 |
53 | FetchContent_GetProperties(googletest)
54 | if(NOT googletest_POPULATED)
55 | FetchContent_Populate(googletest)
56 | add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
57 | endif()
58 |
59 | include(GoogleTest)
60 | ```
61 |
62 | 4. Create a `CMakeLists.txt` in your __project root__ to wire it all together:
63 | ```cmake
64 | cmake_minimum_required(VERSION 3.11)
65 |
66 | project(CodingDojo LANGUAGES CXX)
67 | set(CMAKE_CXX_STANDARD 11)
68 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
69 |
70 | enable_testing()
71 | include(AutoDownloadGTest)
72 |
73 | set(${PROJECT_NAME}_CXX_FLAGS -Wall -Wextra -Werror -g3)
74 | set(${PROJECT_NAME}_DEBUG_CXX_FLAGS -O0)
75 | set(${PROJECT_NAME}_RELEASE_CXX_FLAGS -O3)
76 |
77 | function(add_solution SOLUTION)
78 | add_executable(${SOLUTION} ${SOLUTION}.cc)
79 | target_compile_options(${SOLUTION} PUBLIC
80 | "${${PROJECT_NAME}_CXX_FLAGS}"
81 | "$<$:${${PROJECT_NAME}_DEBUG_CXX_FLAGS}>"
82 | "$<$:${${PROJECT_NAME}_RELEASE_CXX_FLAGS}>")
83 | target_link_libraries(${SOLUTION} PUBLIC gmock_main)
84 | gtest_discover_tests(${SOLUTION} TEST_PREFIX "${SOLUTION}.")
85 | endfunction()
86 |
87 | add_solution(CodingDojo)
88 | ```
89 |
90 | 5. Create a `CodingDojo.cc` file in your __project root__ to test:
91 | ```c++
92 | #include
93 | #include
94 |
95 | class HelloWorld {
96 | public:
97 | std::string say() {
98 | return "Hello, World!";
99 | }
100 | };
101 |
102 | TEST(HelloWorldTest, shouldSayHelloWorld) {
103 | ASSERT_EQ("Hello, World!", HelloWorld().say());
104 | }
105 | ```
106 |
107 | 6. Build and test that all works:
108 |
109 | ```shell
110 | $ mkdir build
111 | $ cd build
112 | $ cmake ../
113 | $ make all test
114 | ```
115 |
116 | You should see an output like below:
117 | ```cmake
118 | [ 10%] Building CXX object _deps/googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
119 | [ 20%] Linking CXX static library libgtest.a
120 | [ 20%] Built target gtest
121 | [ 30%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
122 | [ 40%] Linking CXX static library libgmock.a
123 | [ 40%] Built target gmock
124 | [ 50%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
125 | [ 60%] Linking CXX static library libgmock_main.a
126 | [ 60%] Built target gmock_main
127 | [ 70%] Building CXX object CMakeFiles/CodingDojo.dir/CodingDojo.cc.o
128 | [ 80%] Linking CXX executable CodingDojo
129 | [ 80%] Built target CodingDojo
130 | [ 90%] Building CXX object _deps/googletest-build/googlemock/gtest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
131 | [100%] Linking CXX static library libgtest_main.a
132 | [100%] Built target gtest_main
133 | Running tests...
134 | Test project /var/folders/4s/wtz_xy4d2mz_gw8sclcb8x2c0000gn/T/tmp.BD5tu8Xj/project/build
135 | Start 1: CodingDojo.HelloWorldTest.shouldSayHelloWorld
136 | 1/1 Test #1: CodingDojo.HelloWorldTest.shouldSayHelloWorld ... Passed 0.01 sec
137 |
138 | 100% tests passed, 0 tests failed out of 1
139 |
140 | Total Test time (real) = 0.01 sec
141 | ```
142 |
143 | For more detailed test output run:
144 | ```shell
145 | $ ./CodingDojo
146 | Running main() from gmock_main.cc
147 | [==========] Running 1 test from 1 test case.
148 | [----------] Global test environment set-up.
149 | [----------] 1 test from HelloWorldTest
150 | [ RUN ] HelloWorldTest.shouldSayHelloWorld
151 | [ OK ] HelloWorldTest.shouldSayHelloWorld (0 ms)
152 | [----------] 1 test from HelloWorldTest (0 ms total)
153 |
154 | [----------] Global test environment tear-down
155 | [==========] 1 test from 1 test case ran. (0 ms total)
156 | [ PASSED ] 1 test.
157 | ```
158 | __You are all set now with your C++ project__
159 |
160 | [cmake]: https://cmake.org
161 | [googletest]: https://github.com/google/googletest
--------------------------------------------------------------------------------