ITeye博客

在Maven2中不可以运行Junit4中的Before吗?

iamlibo · 2007-05-20 18:46 · Markdown

在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 都没有运行.这样一些初始化资源就不行了.

谁能给个正解??

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。