如何从JUnit测试读取Maven属性? [英] How to read Maven properties from JUnit test?

查看:96
本文介绍了如何从JUnit测试读取Maven属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Maven 3.0.3与JUnit 4.8.1一起使用.在我的JUnit测试中,如何阅读在Maven pom.xml文件中定义的project.artifactId?在我的pom中,我有

I'm using Maven 3.0.3 with JUnit 4.8.1. In my JUnit test, how do I read the project.artifactId defined in my Maven pom.xml file? In my pom, I have

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.myco.pplus2</groupId>
<artifactId>pplus2</artifactId>

但这在我的JUnit测试中无法获取工件ID ...

But this isn't working within my JUnit test to gete the artifact id ...

@Before
public void setUp() { 
    ...        
    System.out.println( "artifactId:" + System.getProperty("project.build.sourceEncoding") ); 
}   // setUp

以上输出"artifactId:null".无论如何,感谢您的帮助,-戴夫(Dave)

The above outputs "artifactId:null". Anyway, appreciate any help, - Dave

推荐答案

查看

Look at the systemPropertyVariables (and friends) for surefire. It does what you want. AFAIK there is no way to just pass all the maven properties without listing them.

这篇关于如何从JUnit测试读取Maven属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆