I believe that the development of software - something more than a job. I see myself as a craftsman, which is every day trying to get better. The most "simple" way to do this - to find a few good tools and answer the following questions:
- When should I use the instrument X?
- How should I use the instrument X?
Automated testing - a very important part of software development, but developers blog posts about a little-used tools. This article also allow you to look into my "toolbox". I'll talk about 12 libraries and frameworks that I use for writing unit- and integration test, and provides links to pages that help you understand how to use them.
Look into my toolbox
Before you can use the tools described below, you need to set up an assembly that automatically starts the integration and unit-tests. I have 2 notes on this subject:
- Integration testing with Maven describes how we can customize the Maven-assembly with the integration and unit-tests in different directories.
- Getting Started with Gradle: integration testing with the plugin TestSets describes the same for Gradle.
Now you are ready to look at my instruments more closely. I divided them into categories to make it easier to navigate.
So, here are 12 tools that I use in the integration and unit-testing.
Starting the test
JUnit - a framework that I use for unit-, and for integration tests. I like it very much, because he is the most popular, so has many extensions. Also, if you have a problem - a solution will be easy.
NestedRunner - extension for JUnit, which allows you to run the test methods of nested classes. Like NestedRunner for several reasons:
- You can replace the long method names in the class hierarchy in the style of BDD;
- You can get rid of duplicate code by moving it to the installation methods in the relevant sub-classes;
- You can declare constants in nested classes and associate them with the test that these constants are needed.
davaprovider-junit - extension for JUnit, which allows to write tests using parameterized TestNG as the dataprovider. This is a big improvement over the usual way of writing parameterizedtests, which, frankly, not very much.
Additionally:
- Unit-testing with JUnit describes how to write tests with JUnit 4.X.
- Writing a "clean" test: the beauty of the small size is about solving problems related to writing "pure" test.
- Getting Started with dataprovider-junit.
- Features dataprovider-junit.
- junit-dataprovider - an alternative to parameterized classes JUnit describes how to switch from the standard parameterized tests to tests that use junit-dataprovider.
Layouts plugs substitution
Mockito - the most popular framework with support for prototyping unit-tests. I like it because of the simple API, many useful features and excellentdocumentation.
Greenmail - e-mail server that supports SMTP, POP3 and IMAP-enabled SSL-connection. I like it because of the ease of use. When I was looking for a debug server e-mail, reviewing several alternatives, focused on Greenmail, because it worked exactly as I wanted.
MockFtpServer - a library that provides two different implementations of FTP-server ("cap" and "snag"), which can be used to test variousscenarios. If you need to test code that interacts with the FTP-server, our choice - MockFtpServer.
Additionally:
- Reference Mockito - a great example of the reference documentation, which really helps.
- Integration testing IMAP, SMTP and POP3 via Greenmail.
- Getting Started with FakeFtpServer.
- Getting Started with StubFtpServer.
- What to choose: FakeFtpServer or StubFtpServer? Will decide which implementation of the FTP-server is needed for a particular test.
Assertions
Hamcrest provides tools for writing assertions (assertions) for unit- and integratsionnayh tests.I use it with Spring MVC TestFramework.
AssertJ provides a flexible API for writing statements with useful error messages improves the readability of the test code, allows you to turn the tests into executable specifications that adhere to the desired object-oriented language.
Additionally:
- Tutorial Hamcrest.
- Using Hamcrest testing tells you how to use Hamcrest for writing tests, and how to expand its capabilities with custom modules.
- Overview Core AssertJ.
- Transform statements in the domain-specific language describes how to create custom approval AssertJ.
- Writing clean test: replacement allegations object-oriented language. It tells why we need to replace the standard JUnit own statements that use a true object-oriented language.
Test data access code
H2 - fast database is useful to write integration tests that run on the local development machine.
DbUnit - extension for JUnit, which can be used to initialize a database to a known state before each test integration and filling the database that contains the data. In DbUnit it has its flaws, but it is a very useful tool that allows you to share test data and test code.
Additionally:
- DbUnit Core Components describes the key components of DbUnit, the knowledge of which is necessary for writing tests using DbUnit.
- Best practices DbUnit provides five rules of writing the best tests for data access code.
- Writing tests for the data access code to help you write tests deterministic access to the data that verify the right thing, easy to read and maintain.
Spring Testing Applications
Test Spring - Swiss army knife for writing automated tests. It provides first-class support for writing unit- and integration tests for applications using Spring.
Test DbUnit Spring - integrate DbUnit who want to get into String Test. If you need to write tests for data access application using Spring, and a relational database, the Spring Test DbUnit to help you.
Additionally:
- Guide to Spring. Section 11: Test.
- Of Guidelines on the Spring MVC Test tells about writing unit- and integration tests for controllers Spring MVC.
- Of Guidelines on the Spring Data JPA: integration testing.
- Spring is best: the use of Null-value data sets DbUnit.
- Spring is good: reset autoincrement field before each test method.
Комментариев нет:
Отправить комментарий