JHipster comes with an extensive set of tests, and each generated application has:
Optionally, JHipster can also generate:
We have two goals in generating those tests:
mvn clean test
gulp test
All those tests will be generated in the standard Maven src/test folder.
src/test
Integration tests are done with the Spring Test Context framework, and are located in the src/test/java folder. JHipster will launch a specific Spring test context, which will be re-used along all tests, as:
src/test/java
This Spring test context will use a specific test database to execute its tests:
Those tests can be run directly in your IDE, by right-clicking on each test class, or by running mvn clean test (or ./gradlew test if you run Gradle).
./gradlew test
Limitations: if the generated entities have validation enabled, JHipster is not enable to generate the correct values depending on the validation rules. Those rules can be so complex, for example if a Regex pattern is used, that this just not possible. In this case, the tests will fail validation, and the default values used in the test will need to changed manually, so they can pass the validation rules.
UI tests come in two flavors with JHipster: unit tests with KarmaJS, and integration tests with Protractor. Only KarmaJS is provided by default, but if you want to have a good test coverage of your application, we recommend that you use both tools together.
UI unit tests are written in Jasmine and run with Karma.js and PhantomJS, and are located in the src/test/javascript/spec folder.
src/test/javascript/spec
Those tests will mock up the access to the application's REST endpoints, so you can test your UI layer without having to launch the Java back-end.
./node_modules/karma/bin/karma start src/test/javascript/karma.conf.js --debug
describe('...', function() {
fdescribe('...', function() {
UI integration tests are done with Protractor, and are located in the src/test/javascript/e2e folder.
src/test/javascript/e2e
Those tests will launch a Web browser and use the application like a real user would do, so you need to have a real application running, with its database set-up.
Those tests can be run using gulp protractor or gulp itest.
gulp protractor
gulp itest
Performance tests are done with Gatling, and are located in the src/test/gatling folder. They are generated for each entity, and allows to test each of them with a lot of concurrent user requests.
src/test/gatling
Gatling tests can be run with Maven, by running mvn gatling:execute. If you have several tests, JHipster will ask which test should be run.
mvn gatling:execute
Warning! At the moment, those tests do not take into account the validation rules you may have enforced on your entities. You will anyway need to change those tests, according to your business rules, so here are few tips to improve your tests:
Administration > Logs
org.springframework
debug
console log
Behaviour-driven development (BDD) is available using Cucumber, with its JVM implementation.
Gherkin features will have to be written in your src/test/features directory.
src/test/features