Software Engineering Done Right

How to really apply common sense knowledge and principles — s01e01

Introduction

Best-Practices

The Series

The Scene

The Start

Hello Arc-E-Tect

D:\Projects\arc-e-tect\phonebook>gradle init
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Swift
Enter selection (default: Java) [1..5] 3
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1
Select test framework:
1: JUnit 4
2: TestNG
3: Spock
4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4] 4
Project name (default: phonebook): PhonebookSource package (default: Phonebook): com.arc_e_tect.blog.phonebook> Task :init
Get more help with your project: https://docs.gradle.org/6.0.1/userguide/tutorial_java_projects.html
BUILD SUCCESSFUL in 37s
2 actionable tasks: 2 executed
D:\Projects\arc-e-tect\phonebook>
Directory of D:\Projects\arc-e-tect\phonebook
...
16-02-2020 18:21 <DIR> .
16-02-2020 18:21 <DIR> ..
16-02-2020 18:21 160 .gitattributes
16-02-2020 18:21 108 .gitignore
16-02-2020 18:21 <DIR> .gradle
16-02-2020 18:21 1.218 build.gradle
16-02-2020 18:21 <DIR> gradle
16-02-2020 18:21 5.764 gradlew
16-02-2020 18:21 2.942 gradlew.bat
16-02-2020 18:21 368 settings.gradle
16-02-2020 18:21 <DIR> src
...
D:\Projects\arc-e-tect\phonebook>
D:\Projects\arc-e-tect\phonebook>gradlew buildBUILD SUCCESSFUL in 2s
7 actionable tasks: 7 executed
D:\Projects\arc-e-tect\phonebook>
D:\Projects\arc-e-tect\phonebook>gradlew run> Task :run
Hello world.
BUILD SUCCESSFUL in 1s
2 actionable tasks: 1 executed, 1 up-to-date
D:\Projects\arc-e-tect\phonebook>
D:\Projects\arc-e-tect\phonebook>

Testing

TDD

AppTest.java

package com.arc_e_tect.blog.phonebook;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class AppTest {
@Test
void appHasAGreeting() {
App classUnderTest = new App();
assertNotNull(classUnderTest.getGreeting(),
"app should have a greeting");
}
}
@Test
void appHasHelloInforAsGreeting() {
App classUnderTest = new App();
assertEquals(“Hello Arc-E-Tect.”, classUnderTest.getGreeting(),
“app should have a greeting”);
}
D:\Projects\arc-e-tect\phonebook>gradlew build> Task :test FAILEDAppTest > appHasHelloInforAsGreeting() FAILED
org.opentest4j.AssertionFailedError at AppTest.java:20
2 tests completed, 1 failedFAILURE: Build failed with an exception.* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///D:/Projects/arc-e-tect/phonebook/build/reports/tests/test/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.orgBUILD FAILED in 2s
7 actionable tasks: 1 executed, 6 up-to-date
D:\Projects\arc-e-tect\phonebook>
public String getGreeting() {
return “Hello Arc-E-Tect.”;
}
D:\Projects\arc-e-tect\phonebook>gradlew buildBUILD SUCCESSFUL in 1s
7 actionable tasks: 7 up-to-date
D:\Projects\arc-e-tect\phonebook>

Concluding

Disclaimer

Credits

Some people see things and ask ‘Why?’ I dream of things and ask ‘Why not?’

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store