cn.devit.maven:testing-maven-plugin

Generate R.java for src/test/resources.

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

cn.devit.maven
ArtifactId

ArtifactId

testing-maven-plugin
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

cn.devit.maven:testing-maven-plugin
Generate R.java for src/test/resources.
Project URL

Project URL

https://github.com/devitcn/testing-maven-plugin
Project Organization

Project Organization

Devit.cn
Source Code Management

Source Code Management

https://github.com/devitcn/testing-maven-plugin

Download testing-maven-plugin

How to add to project

<plugin>
    <groupId>cn.devit.maven</groupId>
    <artifactId>testing-maven-plugin</artifactId>
    <version>0.3.0</version>
</plugin>

Dependencies

compile (3)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 2.0
org.codehaus.plexus : plexus-utils jar 3.0.8
org.apache.maven : maven-project jar 2.2.1

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.2

test (2)

Group / Artifact Type Version
junit : junit jar 4.8.2
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

给src/test/resource中的文件生成一个静态类,类似android中的R

Generate a static class for all files in src/test/resource(like android R.java)

  • 方便引用,可以直接代码提示
  • 用编译错误推动测试代码维护,提前发现FileNotFound异常
  • 不能成为JAVA变量名的字符都转换成了下划线,例如首字符是数字,字符,各类标点符号。

Example

There are two files resource in src/test/resources:

test-data.txt
features/1.txt

Then will Generate com/foo/R.java at target/generated-test-sources/path/

package com.foo

import java.io.File;

public final class R
{
  public static final File dir = new File("src/test/resources/");
  
  public static class features
  {
    public static final File dir = new File("src/test/resources/features");
    public static final File _1_txt = new File("src/test/resources/features/1.txt");
  }
  
  public static final File test_data_txt = new File("src/test/resources/sample-1.txt");
}

Usage

在pom.xml中增加如下build配置:

<plugin>
    <groupId>cn.devit.maven</groupId>
    <artifactId>testing-maven-plugin</artifactId>
    <version>0.3.0</version>
    <executions>
      <execution>
        <goals><goal>path</goal></goals>
        <phase>generate-test-sources</phase>
      <configuration>
        <packageName>com.foo.bar</packageName>
      </configuration>
      </execution>
    </executions>
</plugin>

支持两个参数

packageName :指定生成的类的包名,默认会取groupdId

className:指定生成的类名,默认会取R,也可以指定类全名,这时会忽略packageName参数

cn.devit.maven

Devit.cn

Programming relationships ,国际化的编程,

Versions

Version
0.3.0
0.2.0
0.1.0
0.0.1