Jasmine JUnit tests take advantage from the Annotation based approach of JUnit 4.x. All annotations listed below can be found in the sourcecode under package com.metservice.jasminerunner.junit
Mark the class as a Junit with specialized runner. A Jasmine JUnit class is annotated by
@RunWith(JasmineTestRunner.class)
Specify the browser to run the test on. One or more Browser types can be used for the same test suite. Supported are: FIREFOX, SAFARI, CHROME, IPHONE, INTERNET_EXPLORER, ANDROID, HTML_UNIT (restricted)
@Browsers(FIREFOX)
Define where to find the root of the web application (relative to project path). multiple roots possible, first hit is served:
@ServerConfiguration(sourceBase = {"/src/main/webapp", "/src/test/javascript"})
@RequiredScripts({"/config.js", "/lib/require.js/require.js", "/lib/underscore.js" /*,...*/ })
This adds the mentioned scripts to the test environment before running the jasmine spec. All this scripts will be loaded before the Jasmine test suite runs. Base path for scripts is the root of the server, see above. The scripts of Jasmine don't need to be listed, they are added by default. They are not required in your project source code folder either.
When added to class, this affects all tests in the JUnit suite, when added to test method, it affects only the specs given in that test.
If present for both class and test, both are applied (avoid duplicates!).
@MockResource(path = "/module/modules", content = "[{}]")
@MockResource(path = "/module/modules", location = "mockReturn.js")
Either content or location must be given. If the tests requests the resource of this path, either content is returned, or the content of the given location is returned. Base path of location is the parent folder of the executed jasmine spec. To add multiple MockResource entries per test, use this annotation:
@MockResources([@MockResource...])
:::java
@SpecFile(srcRoot = "/src/test/javascript/module/portlets/lightning/search", testBasePath = "/module")
public String[] testMapSearch() {
return new String[] {
"MapSearch_spec.js",
"MapSearchResultsView_spec.js",
"SearchableClientLocations_spec.js",
"SearchableModel_spec.js",
"SearchCriteriaModel_spec.js",
"SearchResultsModel_spec.js"
};
}
srcRoot is the path relative to project root that holds the spec files
testBasePath is where to load this script from during the test - to work well with relative file links
the test method returns a list of spec file names to run within the environment defined by this test method in this test class