Fix release of MSP port when MSP and MSP telemetry are used on the same
[betaflight.git] / docs / development / Development.md
blob1ae4d9dd24f6fbd3fe0d30829dd6915a63fafe8a
1 #Development
3 This document is primarily for developers only.
5 ##Unit testing
7 Ideally, there should be tests for any new code. However, since this is a legacy codebase which was not designed to be tested this might be a bit difficult.
9 If you want to make changes and want to make sure it's tested then focus on the minimal set of changes required to add a test.
11 Tests currently live in the `test` folder and they use the google test framework.  
12 The tests are compiled and run natively on your development machine and not on the target platform.
13 This allows you to develop tests and code and actually execute it to make sure it works without needing a development board or simulator.
15 This project could really do with some functional tests which test the behaviour of the application.
17 All pull requests to add/improve the testability of the code or testing methods are highly sought!
19 Note: Tests are written in C++ and linked with with firmware's C code.
21 ##General principals
23 1. Name everything well.
24 2. Strike a balance between simplicity and not-repeating code.
25 3. Methods that return a boolean should be named as a question, and should not change state.  e.g. 'isOkToArm()'
26 4. Methods that start with the word 'find' can return a null, methods that start with 'get' should not.
27 5. Methods should have verb or verb-phrase names, like `deletePage` or `save`.  Variables should not, they generally should be nouns.  Tell the system to 'do' something 'with' something.  e.g. deleteAllPages(pageList).
28 6. Keep methods short - it makes it easier to test.
29 7. Don't be afraid of moving code to a new file - it helps to reduce test dependencies.
30 8. Avoid noise-words in variable names, like 'data' or 'info'.  Think about what you're naming and name it well.  Don't be afraid to rename anything.
31 9. Avoid comments that describe what the code is doing, the code should describe itself.  Comments are useful however for big-picture purposes and to document content of variables.
32 10. If you need to document a variable do it at the declarion, don't copy the comment to the `extern` usage since it will lead to comment rot.
33 11. Seek advice from other developers - know you can always learn more.
34 12. Be professional - attempts at humor or slating existing code in the codebase itself is not helpful when you have to change/fix it.
35 13. Know that there's always more than one way to do something and that code is never final - but it does have to work.
37 ###Running the tests.
39 The tests and test build system is very simple and based of the googletest example files, it will be improved in due course.
41 ```
42 cd test
43 make
44 ```
46 This will build a set of executable files, one for each `*_unittest.cc` file.
48 You can run them on the command line to execute the tests and to see the test report.
50 You can also step-debug the tests in eclipse and you can use the GoogleTest test runner to make building and re-running the tests simple.
52 The tests are currently always compiled with debugging information enabled, there may be additional warnings, if you see any warnings please attempt to fix them and submit pull requests with the fixes.