How to run integration tests?

In our project, we have many unit tests. They help keep the project well-tested.

In addition to them, we have a set of tests that are unit tests, but depend on some external resource. We call them external trials. For example, they can sometimes access web services.

While unit tests are easy to run, integration tests cannot pass sometimes: for example, due to a timeout error. In addition, these tests may take too long.

Currently, we continue integration / external unit tests only to run them while developing the corresponding functions.

For simple unit tests, we use TeamCity for continuous integration.

How do you run integration module tests and when do they run?

+5
source share
3 answers

In our project, we have a separate set for regular / simple unit tests and a separate set for integration tests. There are two reasons for this:

  • performance: integration tests are much slower
  • Test fragility: integration tests most often fail due to environmental conditions (give false positives).

We use TeamCity as our main continuous integration server and Maven as a build system. To run the tests, we use the following algorithm:

  • We run unit tests inside the Eclipse IDE and before each commit.
  • We run unit tests automatically after each commit on TeamCity agents using Maven mvn clean install
  • TeamCity "main".

, , - TeamCity, "" continuous.build, . : http://confluence.jetbrains.net/display/TCD4/Dependencies+Triggers

( ):

  • "src/it/java" ,
  • maven-surefire-plugin ( / ),
  • Maven "", "src/it/java" ( -Pintegration task.tests).
+2

Maven2: maven-surefire-plugin ( ) maven- ( -).

, .

, , .

Fitnesse . .

Hudson CI.

+3

. 7 .

. - - , .

, . ( - Python)

class SomeIntegrationTest( unittest.TestCase ):
    def setUp( self ):
        testclient.StartVendorMockServer( 18000 ) # port number
        self.connection = applicationLibrary.connect( 'localhost', 18000 )
    def test_should_do_this( self ):
        self.connection.this()
        self.assert...
    def tearDown( self ):
        testClient.KillVendorMockServer( 18000 )

- . , .

class SomeIntegrationTest( unittest.TestCase ):
    def setUp( self ):
        self.connection = applicationLibrary.connect( 'localhost', 18000 )
    def test_should_do_this( self ):
        self.connection.this()
        self.assert...

 if __name__ == "__main__":
     testclient.StartVendorMockServer( 18000 ) # port number
     result= unittest.TextTestRunner().run()
     testclient.KillVendorMockServer( 18000 )
     system.exit( result.failures + result.errors )

, mocked-up .

+1

All Articles