1 <!--- Copyright 2020 Canonical Ltd.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. --->
16 # N2VC Unit Testing Guideline
18 ## Use `test_libjuju.py` as a guideline
20 Even though the Test Cases still have plenty of potential improvements we feel like this file is the most polished of all of them. Therefore it should be used as a baseline of any future tests or changes in current tests for what is the minimum standard.
22 ## Try to use mock as much as possible
24 There are some cases where FakeClasses (which still inherit from Mock classes) are used. This is only for the cases where the construction of the object requires to much additional mocking. Using standard mocks gives more testing possibilities.
26 ## Separate your Test Cases into different classes
28 It is preferrable to have a TestCase Class for each method and several test methods to test different scenarios. If all of the classes need the same setup a Parent TestCase class can be created with a setUp method and afterwards the other TestCases can inherit from it like this:
31 class GetControllerTest(LibjujuTestCase):
34 super(GetControllerTest, self).setUp()
39 It is more important to actually assert the important logic than have a high code coverage but not actually testing the code.
41 These are some of the things that should be always asserted:
43 * Assert all Exceptions are launched correctly.
44 * Assert the return values are the expected ones for **both** succesfull executions and unsuccesful ones.
45 * Assert that all important calls have been called the correct amount of time and with the correct arguments.
46 * Assert that when the method is failing the correct log messages are posted.
47 * Assert that all things to need to be disconnected after execution are correctly disconnected.