COMP23311 24小时速成
Week 1: Building & Testing Open Source Systems
What is software Engineering?
- Building software to Budget + Deadline
- Needs to Deliver sufficient ROI (Return on Investment) + affordable to maintain and change
Typical Software organisation:
- Local Dev
- Dev
- Test
- Live
- End Users
- Acquring Source code
- Build the object code
- Run tests (code review, follow coding standards/documentation procedures, pass automated tests)
Week 2: Understanding Large Software Systems Through Tests
code reading: system domain technical
syntactical/conceptual error/software bugs (faults error flow in source code or system design)
Week 3: Debugging
Debug systematic approach:
-
start with a problem:
replicate the issue -
stablize a problem
describe the problem precisely - isolate the problem
-
tactic: rubber ducking, find common problems, IDE debug tools, test cases, git commit logs
-
strategy: brute force+backtrack+binary search+eliminate
-
-
fix the problem
(mostly the easiest part) - test if the fix is successful
- check similar errors (very important)
JUnit测试用例基本规则:
- test class 以
Test
结尾 - test method 一般建议以
should
开头 (别的其实也可以) - assert一个测试方法中只能有一个
- test method 不要有任何传入参数
Week 4: Cost Estimation
Cost estimation: effort + resources + schedules
WBS: work breakdown structures
100% rule: states that the WBS includes 100% of the work defined by the project scope and captures all deliverables – internal, external, interim – in terms of the work to be completed, including project management.
Week5: Test First Development
Scoping features to manage risk
- incremental dev: Simple ver, in a form that can be used, Minimum marketable feature
- Build on existing components: reuse, adapt, expand
- Control the scope:
ctrl affected:- existing types of obj
- existing functions
- user groups
Release planning
- release date
- user type?
- build on? (reused what?)
- affected types?
- affected functions?
Agile Method: Fail fast (corner stone)
- short iterations
- user stories
- iteration planning/release planning
- evolutionary design
- TFD/TDD Test-first dev (test driven dev 更强)
Test against 3 layer architecture (Presentation logic, Business Logic, Data Logic):
-
Outside-in Approach (gui driver 模拟用户操作)
-
Middle-Out Approach (调用 service layer api)
Role of acceptance tests
evaluate the system’s compliance with the business requirements and verify if it is has met the required criteria for delivery to end users.
Test-first process:
- sketch out expected behavior as acceptance tests (use existing codes, or wishful thinking)
- create test stubs and compile test
- run the test to get a result (red)
- implement the production code stubs
- run the test again (should be green)
Remember in Jenkins:
- grey == not running test
- red == compile failed
- yellow == compile successful, but some tests failed
- green == all tests passed
Failing test:
- fail unit test: you are fucked
- failed pre-passed acceptance test: you are fucked
- failed acceptance test on future features: it’s fine
TAD -> TFD -> TDD: maximise test coverage, maximise fit of production code to test code
Week 6: Git Workflow
Code review:
- buddy review (informal)
-
team-based review (informal)
tool: gerrit (allow code to be held in staging area for code rev, block integration into main branch until pass quality standard)way: walkthrough: sanity check of design (best at the beginning), or correctness of implementation (after or during implementation)
- formal review (formal, inspection, technical review, technical+management)
Code reviewer’s good practice: neutral tone, promiscuory reviewing (轮换检查)
Rules on Commit msg:
Imperative tone, NO COMMA, first line limit to 50 chars, the rest limit to 72 chars, second line leave blank, leave blank between paragraphs, detailed description of the change, integrate bug tracking
Git commit shits:
group coordination+codebase synchronisation, quality assurance
- Merge
- Cherry Pick
- Rebase
- Resolve conflict
- Fast forward
Difference between Merge and conflict:
Merge == preserve feature branch, Rebase == blow up feature branch, no record, look simple and elegent
Git workflow:
- GitFlow Model
- 2 main branches: master develop
- 3 supporting branches: feature hotfix release
- only hotfix branch can fork from master
-
NO FAST FORWARD, NEVER.
-
[branch structure]:
develop <=> master <=> feature
master <=> hotfix, feature <=> develop
release <=> develop, (maybe!) hotfix => develop
-
GitHub Flow
master, feature branches. all work done on feature branchevery commit on master is deployable, test branch in production environment before merging, pull request for code review
-
Trunk-Based Development (主干开发模型)
everyone work in one single trunk branchone can work on local branch, merge to remote branch after get passed in gerrit
every single commit is release ready, high quality commits but no protection against errors
Week 8: Refactoring and Migration
- fixed bugs: corrective
- added feature: adaptive
- refactoring/migration: preventive change (prevent cost)
Patterns of code change:
-
rename method/class
-
covert a var into const
-
convert a local var into a field
-
move a method to another class
Refactoring:
- IDE integrated
- change structure but not behavior
- good tests are essential
- workflow: run tests -> refactor -> run test again
- relatively small changes
Software Migration:
large scope, move some functionality from one context to another (like from MySQL to Couchbase)
Typical Process:
- Ensure behavior which to be migrated is well tested
- Migrate test to fit target context (doesn’t care abstract layer tests)
- Then migrate functionality
- test+fix until all migrated tests passed
- then remove old form migrated tests
9. Design for Testability
Code is easy to test => code is easy and safe to change => good software design
design driven for testability, ensure the code is easy to test
Bad factors:
- Non-deterministic (randomness) code
- Hard-coding/hiding behavior
- Not allowing inheritance/overriding
- Complex/Slow configuration (running excessive shit such as database even if just need to test a simple thing, take more time)
- Break the LAW OF DEMETER (I don’t know, didn’t covered, don’t ask)
Test doubles: (测试替身): a ver of predictable production code object
- Dummies: placeholder, passed but never used
- Stubs: fixed value, canned answers
- Fakes: include simple (usually shitty) logic, (partly) working implementations
- Mocks: basically stub with assertions
10. Patterns
Patterns: distilled wisdom, allow to reuse solutions (experience), provide a shared vocabulary of talking about software design
Group of Patterns:
- Behavioural Patterns (state, strategy)
- Structural Patterns (composite, adaptor)
- Creational Patterns (factory method, singleton)
- Strategy Pattern: 基于不同类对应的策略封装算法
- State Pattern: 封装同一对象基于不同状态的多种行为
- Composite Pattern: 部分-整体组合模式
- Adapter Pattern: 接口转换, wrapper class
- Factory Method: 让子类自己在运行时决定实例化哪个类
- Singleton Pattern: 只让某个类创建唯一的一个对象
Caution:
- No overuse
- No over-engineering
- refactor TOWARD a pattern rather than TO a pattern (把pattern作为参考, 而不是标准)
Pattern的意义:
Make code easy to understand, maintain and modify
11. Risk Management
Risk: possible negative event
Risk exposure = likelihood + impact (potential cost)
Planning:
- Mitigate planning: make it less likely happen + reduce impact
- Contingency Planning: make preparation if it happen, do nothing to reduce likelihood or impact
Tools used for risk management:
- Git for Risk Management: ……
- CI/CD for Risk Management: reduce risk likelihood
CI: Integrate, build, test, report, make testing and building reliable - Automated Test Suite for Risk Management: reduce cost of regression (reduce cost)
a, b : interval
Begin(), End() shike
Before(a, b) => End(a) < Begin(b)
After(a, b) => Begin(a) > End(b)
Meet(a, b) => End(a) = Begin(b)
During(a, b) => Begin(b) < Begin(a) < End(a) < End(b)
Finishes(a, b) => Begin(b) < Begin(a) < End(a) = End(b)
Starts(a, b) => Begin(b) = Begin(a) < End(a) < End(b)
Equals(a, b) => Begin(b) = Begin(a) && End(a) = End(b)
Overlap(a, b) => Begin(a) < Begin(b) < End(a) < End(b)