Integration Test and Functional Test in plone testing explained

Preface

As a plone developer, I have to do writing lots of unittests for our projects, so I had concerned on plone testing documentation from plone’s official site. Usually I learnt from there about two types of testing, `Integration Testing` and `Functional Testing`. Also knew about Testing Layer and how layer fixture is used while making above kind of tests, in other words which layer fixture is appropriate for which testing, i.e for Functional Testing should be used Functional Testing Layer fixture.

Integration Testing Fixture is generally creating a transaction for each test and just abort the transaction after test being done. Single database(demo storage) is whole test layer lifecycle,  there is not possible to do any persistent activity (transaction commit) in side tests code. Beside Functional Testing Fixture provides database (demo storage) for each test and removed during test teardown (making a stack of database for each test and pop up during tear down process), full transaction lifecycle is happened here, even you could do manually commit and/or use of sub-transaction as well.

By naming (Integration Testing, Functional Testing ) and characteristics  of both, I got confused! my thinking was integration test means collection of components (could be some functions from a module or coming from other modules or api methods from different packages) whether working together perfectly, so here we need persistent features (transaction commit) as we might need to add fixture data and should be available outside of session. For functional test, i thought that this about single component (for example: test single function or method of class), so here we don’t need transaction features, but I was completely wrong (my thought was so stupid)

To get rid out of my confusion, I have planned to dig down into online resources. Very first  I am trying understand that what are meaning of Integration test and Functional test , so ask google and found out from stackoverflow what I was looking for! about Functional testing:

Functional testing is when you test the system against the functional requirements of the product. Product/Project management usually writes these up and QA formalizes the process of what a user should see and experience, and what the end result of those processes should be. Depending on the product this can be automated or not.

Now i have better about those terms and why need persistent feature for Functional Testing

When and where should use each testing type

Integration Testing Fixture

This is relatively faster, you should use it as much as possible, until your test needs (commit) persistent feature. Ideal for testing of methods/functions, where you want to test how those are working together.

Functional Testing Fixture

Primary use case is, when you need to test/monitor after commit reaction of each function/component and make sure data goes to database successfully. If you have SqlAlchemy’s transaction integration, this functional testing fixture is mandatory for you, as some exception/error is thrown by SqlAlchemy during data going to be committed. i.e Integrity violation. Another required case is, when your test will need to use test browser, there you must need completion of transaction lifecycle to avail saved data during assertion. Test browser to be working,  you have to use ZServer Layer Fixture (from plone.app.testing) that is making test server for you.

Naturally Functional testing is slower compared to Integration testing , even it will be getting more slower if you attach ZServer fixture. In my previous experiences, i made functional test fixture with integrating zserver fixture and use this fixture for all of tests (i didn’t care if persistent(transaction commit) is required or not, test browser is needed or not!. ), one of cause, there was my lack of knowledge as result small test took so much time. Now i am learning and have some opinion from me! You should make two functional testing fixture, one without zserver fixture and one with zserver. So if any test needs test browser you will go for with zserver fixture. Bellows are example

from plone.testing import z2
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting

MY_FIXTURE = MyFixtureLayer()
MY_INTEGRATION_TESTING = IntegrationTesting(
 bases=(MY_FIXTURE,),
 name='MyFixtureLayer:IntegrationTesting'
)
MY_FUNCTIONAL_TESTING = FunctionalTesting(
 bases=(MY_FIXTURE, ),
 name='MyFixtureLayer:FunctionalTesting'
)
MY_ZSERVER_FUNCTIONAL_TESTING = FunctionalTesting(
 bases=(
 MY_FIXTURE,
 z2.ZSERVER_FIXTURE),
 name='MyFixtureLayer:ZServerFunctionalTesting'
)

 

Anaconda vs Sublimelinter with Jedi for SublimeText

SublimeText is undoubtedly one of the most popular editor right now over million of software / web developers. The developer is using SublimeText as IDE usually, rather than using as plain text editor,  by making  IDE like features with the help from some great packages  available in free of cost.  For python development environment, Anaconda is all-in-one package for transforming to be IDE, in the other hand Sublimtelinter with Jedi combination one of the best method for enabling sublimetext to provide IDE like features. Both two have pros and cons, i will discuss bellows about my experiences for both.

Anaconda

Pros

  1. Most importantly, this all-in-one kind package and with no dependency, that means you don’t have headache to install multiple packages and separate configurations.
  2. Easy configuration and well documented.
  3. Numbers of active contributors and continuous development, see details
  4. Very faster linting process after introducing json server.
  5. McCabe code complexity checker

Cons

  1. Some time I discovered old problem come again with latest version, that is hanging on my sublimetext (may be one of the cause could be for big file (more than ten thousands of line)).
  2. There is no support for flake8, see discussion here. Although  anaconda linting is working with pyflake and pep8 combinely means likely to be same as flake8, but more just pyflake and pep8, flake8 has lots of cool plugins, you will miss those.
  3. Working with json server might easy, depends on Operating System you are using.

Sublimelinter and Sublime-Jedi

Pros

  1. This combination approach is like that you gather all good packages and using it. Sublimelinter is the best linting framework for SublimeText, in the other hand Jedi is one the best autocomplete library that is welly ported to Sublime, thanks author of SublimeJedi
  2. Jedi provides nice (CTRL+SHIFT+G) explorer (Go Defination) feature, you could go to the reference import very quickly, beside you could easily add extra python package paths those will be auto included to Jedi’s sys path.
  3. Sublimelinter is framework for linting, there are lots of plugins available, for python I would like to use flake8 but you may keen to use pylint, that is also available.
  4. Sublimelinter is working very fast and also has lots of configuration options, so that you could customize as your wish.

Cors

  1. I don’t find so much negative side to using this combination. But I find there is not much development activity on Github.
  2. Some rare case, jedi might not working (not sure if it is caused by Sublimetext or jedi itself)

 

We saw the simple comparison between two approach. In my opinion for novice user, they could go with Anaconda as this is very easy to adapted and configure. But in contrast of beginner user of sublimetext, I would suggest, professional developer should definitely with go with Sublimelinter specially if he/she is a full stack developer as it (Sublimelinter) has variety of plugins for different language/markup i.e css, javascript, html, json, yml and more.

Make Anaconda powered SublimeText as powerful Python IDE for full stack development

Like so many SublimeText lovers, Me as a python developer, it is also one of the favorite editor, I am using but I would like to use  it as full featured IDE. You will find many articles, blogs about how SublimeText can be transformed as pure IDE, but here i will discussed about the most easy way to turn your sublimetext as IDE for full stack python development.

Anaconda  is the single package that is capable to make your editor (SublimeText) as IDE for python development. It has almost all IDE like features, i.e linting, autocomplete, etc. You could say this is all-in-one package, with no third party dependency like SublimeLinter . One of the positive things that it is in continuous development by involvement of many contributors, so you can report any bug/error and the highest possibility, we will get the solution. They have very good documentation as well.

Install and Configuration is easy enough, I would suggest you follow instruction  from their official site, for advanced configuration you could follow here. It is good practice that you make user specific settings those are common for all your projects. Follows are example user settings.

{
    "auto_formatting": true,
    "auto_python_builder_enabled": false,
    "anaconda_linting": true,
    "anaconda_linter_phantoms": false,
    "validate_imports": true,
    "enable_signatures_tooltip": false,
    "merge_signatures_and_doc": false,
    "pep8_max_line_length": 120
}

If you saw the example configuration above, I intentionally set the value of  `pep8_max_line_length` is 120 (default is 80), in the other hand you will see that i don’t mention the path of python interpreter because it should goes on project specific settings (*.sublime-project) if you use individual interpreter(i.e virtualenv) for each project.

{
	"build_systems":
	[
		{
			"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
			"name": "PRS:: Anaconda Python Builder",
			"selector": "source.python",
			"shell_cmd": "{virtualenv path}/bin/python -u \"$file\""
		}
	],
	"folders":
	[
		{
			"path": "."
		}
	],
	"settings":
	{
		"python_interpreter": "{virtualenv path}/bin/python"
        }
}  

If you are using buildout for your project development, we have good news for you! There is a recipe plone.recipe.sublimetext for anaconda settings, this recipe will do for you to generate project specific settings. Followings are possible buildout settings for you (but you could do add  more custom option)

[buildout]
parts += 
     sublimetext
[sublimetext]
recipe = plone.recipe.sublimetext
eggs = ${instance:eggs}
anaconda-enabled = True
anaconda-linting-enabled = True
anaconda-completion-enabled = True
anaconda-validate-imports = True