Film opisujący co i jak http://www.youtube.com/watch?v=PAeLK6Yp2P0 Update: plugin do firefoxa
Rapid development z Liveview
Film opisujący co i jak
Update: plugin do firefoxa
Couple of years ago I wasn't a big fan of unit testing. It was obvious to me that well prepared unit tests are crucial though. I didn't known why exactly crucial yet then. I just felt they are important. My disliking to write automation tests was mostly related to the effort necessary to prepare them. Also a spaghetti code was easily spotted in test sources.apply plugin: 'groovy'As you can see the build.gradle file is almost self-explanatory. Groovy plugin is applied to compile groovy code. It needs groovy-all.jar - declared in version 2.0 at dependencies block just next to Spock in version 0.7. What's most important, mentioned Maven repository URL is added at repositories block.
apply plugin: 'idea'
def langLevel = 1.7
sourceCompatibility = langLevel
targetCompatibility = langLevel
group = 'com.tamashumi.example.testwithspock'
version = '0.1'
repositories {
mavenLocal()
mavenCentral()
maven { url 'http://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.0.1'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0-SNAPSHOT'
}
idea {
project {
jdkName = langLevel
languageLevel = langLevel
}
}
<project root>To build a project now you can type command gradle build or gradle test to only run tests.
│
├── build.gradle
└── src
├── main
│ ├── groovy
└── test
└── groovy
apply plugin: 'java'This way if you don't want or just can't deploy Groovy compiled stuff into your production JVM for any reason, still whole goodness of testing with Spock and Groovy is at your hand.
public class SimpleJavaClass {
public int sumAll(int... args) {
int sum = 0;
for (int arg : args){
sum += arg;
}
return sum;
}
}class SimpleGroovyClass {
String concatenateAll(char separator, String... args) {
args.join(separator as String)
}
}class JustASpecification extends Specification {
@Unroll('Sums integers #integers into: #expectedResult')
def "Can sum different amount of integers"() {
given:
def instance = new SimpleJavaClass()
when:
def result = instance.sumAll(* integers)
then:
result == expectedResult
where:
expectedResult | integers
11 | [3, 3, 5]
8 | [3, 5]
254 | [2, 4, 8, 16, 32, 64, 128]
22 | [7, 5, 6, 2, 2]
}
@Unroll('Concatenates strings #strings with separator "#separator" into: #expectedResult')
def "Can concatenate different amount of integers with a specified separator"() {
given:
def instance = new SimpleGroovyClass()
when:
def result = instance.concatenateAll(separator, * strings)
then:
result == expectedResult
where:
expectedResult | separator | strings
'Whasup dude?' | ' ' as char | ['Whasup', 'dude?']
'2012/09/15' | '/' as char | ['2012', '09', '15']
'nice-to-meet-you' | '-' as char | ['nice', 'to', 'meet', 'you']
}
} To run tests with Gradle simply execute command gradle test. Test reports can be found at <project root>/build/reports/tests/index.html and look kind a like this.apply plugin: 'war'in the build.gradle file and create a directory src/main/webapp.
apply plugin: 'groovy'
apply plugin: 'idea'
def langLevel = 1.7
sourceCompatibility = langLevel
targetCompatibility = langLevel
group = 'com.tamashumi.example.testwithspock'
version = '0.1'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.0.5'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
}
idea {
project {
jdkName = langLevel
languageLevel = langLevel
}
}
res/xml/cordova.xml
If whitelist looks fine, the error is most likely caused by inner implementation of Android System. The Android WebView does not allow by default self-signed SSL certs. When app is debug-signed the SSL error is ignored, but if app is release-signed connection to untrusted services is blocked. CordovaWebViewClient.onReceivedSslErrormust be changed.public class MyWebViewClient extends CordovaWebViewClient {
private static final String TAG = MyWebViewClient.class.getName();
private static final String AVAILABLE_SLL_CN
= "example.domain.com";
public MyWebViewClient(DroidGap ctx) {
super(ctx);
}
@Override
public void onReceivedSslError(WebView view,
SslErrorHandler handler,
android.net.http.SslError error) {
String errorSourceCName = error.getCertificate().
getIssuedTo().getCName();
if( AVAILABLE_SLL_CN.equals(errorSourceCName) ) {
Log.i(TAG, "Detect ssl connection error: " +
error.toString() +
„ so the error is ignored”);
handler.proceed();
return;
}
super.onReceivedSslError(view, handler, error);
}
}Next step is forcing yours app to use custom implementation of WebViewClient. public class Start extends DroidGap
{
private static final String TAG = Start.class.getName();
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.init();
MyWebViewClient myWebViewClient = new MyWebViewClient(this);
myWebViewClient.setWebView(this.appView);
this.appView.setWebViewClient(myWebViewClient);
// yours code
}
}That is all ypu have to do if minSdk of yours app is greater or equals 8. In older version of Android there is no class android.net.http.SslErrorSo in class MyCordovaWebViewClient class there are errors because compliator doesn’t see SslError class. Fortunately Android is(was) open source, so it is easy to find source of the class. There is no inpediments to ‘upgrade’ app and just add the file to project. I suggest to keep original packages. Thus after all operations the source tree looks like:![]() |
| Class SslError placed in source tree. |