随笔-112  评论-73  文章-0  trackbacks-0

在Maven2中是可以运行Junit4的.但是@BeforeClass或@Before却不是每运行一个测试方法是运行.

测试代码如下:

        @BeforeClass
        public static void setUp(){
                System.out.println("beforeClass");
        }
        
        @Before
        public void setUp1(){
                System.out.println("before");
        }
        @Test
        public void test1(){
                System.out.println("test 1");
        }
        
        @Test
        public void test2(){
                System.out.println("test 2");
        }

在Eclipse中运行结果是这样的:
beforeClass
before
test 1
before
test 2
这个结果也是正确的.但是在用Maven 测试的时候结果是这样的:

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running cn.nowerp.platform.utils.StringUtilsTest
test 1
test 2
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec

beforeclass 和before 都没有运行.这样一些初始化资源就不行了.

谁能给个正解??

posted on 2007-05-20 18:46 Libo 阅读(2367) 评论(6)  编辑  收藏

评论:
# re: 在Maven2中不可以运行Junit4中的Before吗? 2007-05-20 21:33 | Sunteya
应该是你maven 的版本太低了
要运行 junit4 maven 的版本应该至少是2.0.5 , surefire-plugin 是 2.3 以上好像

你最好下载一个 2.0.6 然后 mvn test -U 看看  回复  更多评论
  
# re: 在Maven2中不可以运行Junit4中的Before吗? 2007-05-21 07:27 | 鱼肠剑
我的Maven的版本就是2.0.6 Junit4.1都是最新版的.
但是surefire-plugin?这个是什么?我没用到啊?  回复  更多评论
  
# re: 在Maven2中不可以运行Junit4中的Before吗? 2007-05-21 08:37 | 阿南
我也遇到这种问题了,ECLIPSE下runJUNIT和MavenTest的方法是不同的结果  回复  更多评论
  
# re: 在Maven2中不可以运行Junit4中的Before吗? 2007-05-21 09:15 | xyz20003
maven-2.0.6,设置了junit-4.3之后,自动下载了surfire-junit4-2.3插件,实验了一下,结果没有问题哦  回复  更多评论
  
# re: 在Maven2中不可以运行Junit4中的Before吗? 2007-05-22 22:19 | Libo
哦.那可能是我的POM.XML中没有加入surfire-junit这个插件的原因.现在可以跑TestNG了.而且有点喜欢它的报告了.因为我用junit好象没看到它生成报告.如果有知道的告诉我一下.(我是说在MAVN2的方式下)  回复  更多评论
  
# re: 在Maven2中不可以运行Junit4中的Before吗? 2007-05-24 18:14 | xyz20003
报告是指report还是指mvn test以后生成的东西?一直看的都是生成的txt报告,没研究过是不是有其他格式的,我觉得平常测试,txt格式的就足够了,要是再生成其他格式的,估计就更慢了。  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: