I spent most of my Saturday sitting at a local .NET Code Camp and picked up some excellent insights in an area that I have not spent much time for many years.
To balance out all the .NET I had my macbook along and was working on some features for my open source project SyrahTest. The first major feature I am working to release is one that will enable a more powerful API for data driven tests than what tools offer today.
First, a couple simple test cases (created using Test Driven Development):
@DataSource(dialect = DataSource.Dialect.JSON, data = "{ token: \"Class Value\"}")
public class DataSourceAnnotationTest {
@Test
public void replaceTokenInTestMethodAnnotatedWithDataSourceFromClass() {
IDataSource dsc = DataStore.get().getDataSourceInContext();
String result = new DefaultVariableResolver().resolveVariables("some ", dsc);
assertEquals("some Class Value", result);
}
@DataSource(dialect = DataSource.Dialect.JSON, data = "{ token: \"Method Value\"}")
@Test
public void replaceTokenInTestMethodAnnotatedWithDataSource() {
IDataSource dsc = DataStore.get().getDataSourceInContext();
String result = new DefaultVariableResolver().resolveVariables("some ", dsc);
assertEquals("some Method Value", result);
}
}
And an explanation:
@Test
@DataSource(dialect = DataSource.Dialect.JSON, location="/testdata/stander-user-flow.json")
public void login(){
LoginPage login = PageFactory.getLogin();
HomePage home = loginPage.login("", "");
home.clickLinkByText("");
...
}
Future features and examples will illustrate how complex data structures can be composed to keep test data maintainable and test code readable at the same time.
It is worth mentioning that the blog you are reading is being hosted for free on GitHub Pages which has excellent support for building and instantaneously redeploying Jekyll content.
And I was delighted last night when in about 15 minutes I was able to sign up with Travis CI, enable my git project, configure my build, and successfully run my syrahtest-jvm build.
Travis provides a cloud based build service free to any open source project, as well as a paid offering. I’m still exploring its feature set and determining the best way to get my build artifacts into a central maven repository.
Since it wasn’t painfully obvious, for anyone getting started with TravisCI I recommend the following:
gem install travis
.Run travis init
in your project workspace. Examine the generated file and make any additions or changes. Mine only required two lines:
yaml
language: java
jdk: oraclejdk8
Another free provider (for open source projects) that has direct integration with TravisCI is Codecov Their site provides simple setup instructions for Maven, but if you’re using gradle I found this page to be accurate and easy to follow: http://vorba.ch/2015/java-gradle-travis-jacoco-codecov.html