a11n / lint-junit-rule Goto Github PK
View Code? Open in Web Editor NEWA JUnit rule which allows unit testing of custom Lint rules.
License: MIT License
A JUnit rule which allows unit testing of custom Lint rules.
License: MIT License
Fixed on #16
Showcase usage of this rule.
Emphasize standard approach vs. JUnit4 approach.
In our project, it's fail to resolve this library from jcenter
Here is the gradle script
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$GRADLE_PLUGIN_VERSION"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_PLUGIN_VERSION"
classpath "com.neenbedankt.gradle.plugins:android-apt:$APT_PLUGIN_VERSION"
classpath "com.novoda:bintray-release:$BINTRAY_PLUGIN_VERSION"
classpath "com.netflix.nebula:gradle-extra-configurations-plugin:$CONFIG_PLUGIN_VERSION"
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'java'
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_7
configurations {
lintChecks
}
dependencies {
compile "com.android.tools.lint:lint-api:$LINT_VERSION"
compile "com.android.tools.lint:lint-checks:$LINT_VERSION"
testCompile "junit:junit:$JUNIT_VERSION"
testCompile "com.android.tools.lint:lint:$LINT_VERSION"
testCompile "com.android.tools.lint:lint-tests:$LINT_VERSION"
testCompile "com.android.tools:testutils:$LINT_VERSION"
testCompile "de.ad:lint-junit-rule:0.3.0"
testCompile 'de.ad:lint-assertj:0.3.0'
testCompile 'de.ad:lint-hamcrest:0.3.0'
lintChecks files(jar)
}
jar {
manifest {
attributes("Lint-Registry": "permissions.dispatcher.PermissionDispatcherIssueRegistry")
}
}
Error message
* What went wrong:
Could not resolve all dependencies for configuration ':lint:testCompile'.
> Could not find de.ad:lint-junit-rule:0.3.0.
Searched in the following locations:
https://jcenter.bintray.com/de/ad/lint-junit-rule/0.3.0/lint-junit-rule-0.3.0.pom
https://jcenter.bintray.com/de/ad/lint-junit-rule/0.3.0/lint-junit-rule-0.3.0.jar
Required by:
PermissionsDispatcher:lint:unspecified
> Could not find de.ad:lint-assertj:0.3.0.
Searched in the following locations:
https://jcenter.bintray.com/de/ad/lint-assertj/0.3.0/lint-assertj-0.3.0.pom
https://jcenter.bintray.com/de/ad/lint-assertj/0.3.0/lint-assertj-0.3.0.jar
Required by:
PermissionsDispatcher:lint:unspecified
> Could not find de.ad:lint-hamcrest:0.3.0.
Searched in the following locations:
https://jcenter.bintray.com/de/ad/lint-hamcrest/0.3.0/lint-hamcrest-0.3.0.pom
https://jcenter.bintray.com/de/ad/lint-hamcrest/0.3.0/lint-hamcrest-0.3.0.jar
Required by:
PermissionsDispatcher:lint:unspecified
There seems no jars in jcenter. Check this https://jcenter.bintray.com/de/ad/
Could you upload jar file? or am I missing something?
Thanks in advance.
The standard LintDetectorTest
features two approaches to load test resources:
While the first approach is already covered by lint-junit-rule it would be convenient to also feature the second approach in order to allow inline declaration of test resources.
Could you give me a sample test case for .java file?
@RunWith(JUnit4.class)
public class LintTestCase extends TestCase {
@Rule
public Lint lint = new Lint(new PermissionDispatcherDetector(), PermissionDispatcherDetector.ISSUE);
@Test
public void testFoo() throws Exception {
List<Warning> lintResult = lint.files("MainActivity.java");
assertThat(lintResult).hasWarnings(1).in("MainActivity.java");
}
}
This code does not work since it claims there is no MainActivity.java
, so changed it to
@RunWith(JUnit4.class)
public class LintTestCase extends TestCase {
@Rule
public Lint lint = new Lint(new PermissionDispatcherDetector(), PermissionDispatcherDetector.ISSUE);
@Test
public void testFoo() throws Exception {
- List<Warning> lintResult = lint.files("MainActivity.java");
+ List<Warning> lintResult = lint.files("MainActivity.class");
assertThat(lintResult).hasWarnings(1).in("MainActivity.java");
}
}
And now it run the test case. However, I want to test the lint for MainActivity.java
not MainActivity.class
because .java file contains annotations with @Retention(RetentionPolicy.SOURCE)
which is deleted in .class in compile time.
Thanks in advance.
lint-junit-rule
--> library
--> sample
--> harmcrest-matcher
--> assertj-assertion
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.