Assuming you are using PHPUnit to write integration tests, the first step is to make sure your environment is correctly configured.
For that you will need to have an empty database in place and use the correct PHPUnit configuration file.
Integration Test Environment Setup
To specify the credentials for the test database use this file:
{magento_root}/dev/tests/integration/etc/install-config-mysql.php
And the phpunit configuration file can be found in the following path:
{magento_root}/dev/tests/integration/phpunit.xml
Running Integration Tests
Once you have your test environment configured you are ready to create your first test.
I think nothing stops you from put them anywhere but usually your tests go into: {magento_root}/app/code/{vendor}/{extension_name}/Test/Integration/...
Integration test examples
For integration test examples I tend to look at: {magento_root}/dev/tests/integration/testsuite/Magento
There are many examples of integration test for blocks, controllers, models, etc.
A good and simple example is this
{magento_root}/dev/tests/integration/testsuite/Magento/Contact/Controller/IndexTest.php
namespace Magento\Contact\Controller;
/**
* Contact index controller test
*/
class IndexTest extends \Magento\TestFramework\TestCase\AbstractController
{
public function testPostAction()
{
$params = [
'name' => 'customer name',
'comment' => 'comment',
'email' => 'user@example.com',
'hideit' => '',
];
$this->getRequest()->setPostValue($params);
$this->dispatch('contact/index/post');
$this->assertSessionMessages(
$this->contains(
"Thanks for contacting us with your comments and questions. We'll respond to you very soon."
),
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
);
}
}
For more information take a look at this link:
http://devdocs.magento.com/guides/v2.0/test/integration/integration_test_execution.html
Hope it helps.