-1

I work on my thesis and it's about softwaretesting. The programming language is Java. I have a huge program with over 450.000 lines of code (without comments and blankspaces). There are also many JUnit-tests.

My question right now is: How can I get to know if a test is a unittest or an intergrationtest?

My ideas: Can I use the execution time of the tests? Or can I measure the performance of the CPU?

Do you have any tips? Do you have more experience in softwaretesting? I am not new to this, but this case is a bit new and huge for me...

Thank you in advance! :)

J K Fan
  • 1
  • 2
  • This question has been answered several times before on SO. From someone working on a thesis about software testing I would have expected the ability to do a bit of research before asking this kind of question. – Dirk Herrmann Mar 30 '20 at 13:24

2 Answers2

1

Alexis described the difference between unit and integration tests completely above, but I felt the need to chime in on the particularities of java and how to write and notice the difference between unit and integration tests.

Unit Tests

Generally for unit tests, a mocking framework is used to mock certain dependencies of a particular class and of a particular method. Since with unit tests, we only want to test a single unit of the code (class methods) we don't want to have to worry about the other classes that method communicates with, so we mock those external dependencies and often verify that the method call to those external dependencies was carried out, without actually running the external method.

Mocking is a powerful tool to write strong tests for your application and it encourages developers to write clean, well-designed and loosely-coupled code.

A common example you will see throughout a java project is the Mockito Framework. I advise reading more on the topic here.

Integration Tests

"Testing performed to expose defects in the interfaces and in the interactions between integrated components or systems."

In java terms, this often refers to the interaction between classes. How class A calls class B and ensuring the link between them works correctly in regard to data transmission, error handling and control flow. Integration tests don't typically use a mocking framework but in-practice they can. Generally you want to fully test the component interactions without mocking out the dependency link. However, this depends on your needs in regard to application design. More information on this can be found here

Typically with integration tests, the database is tested regarding the CRUD (Create-Read-Update-Delete) operations to it. Unit tests have no connection to a database. This is because tests requiring a database connection will have side effects by their very nature. There is leakage from the concept of testing a "single unit" of your code. Therefore, normally the database is tested from integration tests and up.

Requiring this database connection will often cause your integration tests to run dramatically slower than your unit tests. This is due to needing to roll up the database for each set of transactions for a test class and often if you're using an IOC container (like Spring) then further overhead to time will exist. Typically, for integration tests we use a test database, rather than the real database, and is often in-memory.

In summary

If your project is designed well, the unit tests and integration tests should be segregated by package. It makes sense conceptually, and architecturally it is a better approach for developers to adapt to and feel comfortable with. It also completely draws that line between what is an integration test and what is a unit test.

Unit tests are very fast and should be the foundation of your application test suite. Integration tests can be slow in most cases due to requiring a database connection but can cover more variants than a unit test can.

Unit tests typically use a mocking framework to mock external dependencies. Integration tests typically use the real dependency objects for testing.

Unit tests should not have a database connection. Integration tests typically do have a connection to a test database.

Shane Creedon
  • 1,573
  • 1
  • 14
  • 18
  • Thank you for the help. I know that was the difference between the tests, but your detailed summary pushed me (I hope so) to the right direction. Because I want to know if there are any tools or stuff, which is showing me: This is an integrationtest. This is an unittest. But as you say, in my project the tests are just into one folder: test. So now I need to check the character of each test, like DB connections. – J K Fan Mar 29 '20 at 15:20
0

There are tons of articles/books about this and with a single query in Google you will find more, but in short:

Unit tests are the tests that test only the smallest unit (in Java the smallest unit is a method) in isolation.

Integration tests test the communication/collaboration between dependent units (in Java you might test that certain classes communicate properly).

There is no specific hint or annotation that declare your tests as Units Tests or Integration Tests, you have to dive on the test and figure it out.

You can measure the execution time of the tests really easily. There are a lot of tools for that but the Intellij (which is the most common IDE for Java) has a built-in feature for that. In the picture, you can see the execution time of the test suite printed by this IDE.

enter image description here

Alexis Pavlidis
  • 1,080
  • 1
  • 11
  • 21
  • Thank you. This is my first step now. So time is a valid measurement. I also look and google about some measurments for this tests. I wanted to know if there is more or some hidden knowledge I should know about it... :) – J K Fan Mar 28 '20 at 11:08