junit3

How to provide data files for android unit tests

我的未来我决定 提交于 2019-11-27 12:33:35
I am developing software that loads information from XML files using Android's implementation of java.xml.parsers.DocumentBuilder and DocumentBuilderFactory. I am writing unit tests of my objects and I need to be able to provide a variety of xml files that will exercise the code under test. I am using Eclipse and have a separate Android Test Project. I cannot find a way to put the test xml into the test project such that the code under test can open the files. If I put the files in /assets of the test project, the code under test cannot see it. If I put the files in the /assets of the code

Specifying an order to junit 4 tests at the Method level (not class level)

本秂侑毒 提交于 2019-11-27 11:07:13
I know this is bad practice, but it needs to be done, or I'll need to switch to testng . Is there a way, similar to JUnit 3's testSuite, to specify the order of the tests to be run in a class? Michael D If you're sure you really want to do this: There may be a better way, but this is all I could come up with... JUnit4 has an annotation: @RunWith which lets you override the default Runner for your tests. In your case you would want to create a special subclass of BlockJunit4ClassRunner , and override computeTestMethods() to return tests in the order you want them executed. For example, let's

setUp/tearDown (@Before/@After) why we need them in JUnit?

◇◆丶佛笑我妖孽 提交于 2019-11-27 11:05:24
I believe that we are all know that setUp (@Before) will execute before any test method and tearDown(@After) will execute after test method. Also we know that Junit will create one instance of Test per test method . my question is that can we just move setUp method content to class Constructor and remove setUp method? is there any specific reason to keep setUp method? This (old) JUnit best practices article puts it like this: Do not use the test-case constructor to set up a test case Setting up a test case in the constructor is not a good idea. Consider: public class SomeTest extends TestCase

Does Junit reinitialize the class with each test method invocation?

北城余情 提交于 2019-11-27 05:55:53
问题 When i run the below code, both test cases come true: import static junit.framework.Assert.assertEquals; import org.junit.Test; public class MyTest{ private int count; @Before public void before(){ count=1; } @Test public void test1(){ count++; assertEquals(2, count); } @Test public void test2(){ count++; assertEquals(2, count); } } EXPECTED BEHAVIOUR test1 - success test2 - fail(as expected that count will become 3) ACTUAL BEHAVIOUR test1 - success test2 - success Why junit is reinitializing

Maven 3 and JUnit 4 compilation problem: package org.junit does not exist

佐手、 提交于 2019-11-27 00:49:25
问题 I am trying to build a simple Java project with Maven. In my pom-file I declare JUnit 4.8.2 as the only dependency. Still Maven insists on using JUnit version 3.8.1. How do I fix it? The problem manifests itself in a compilation failure: "package org.junit does not exist". This is because of the import statement in my source code. The correct package name in JUnit 4.* is org.junit.* while in version 3.* it is junit.framework.* I think I have found documentation on the root of the problem on

How to provide data files for android unit tests

半城伤御伤魂 提交于 2019-11-26 16:03:38
问题 I am developing software that loads information from XML files using Android's implementation of java.xml.parsers.DocumentBuilder and DocumentBuilderFactory. I am writing unit tests of my objects and I need to be able to provide a variety of xml files that will exercise the code under test. I am using Eclipse and have a separate Android Test Project. I cannot find a way to put the test xml into the test project such that the code under test can open the files. If I put the files in /assets of

setUp/tearDown (@Before/@After) why we need them in JUnit?

匆匆过客 提交于 2019-11-26 15:25:53
问题 I believe that we are all know that setUp (@Before) will execute before any test method and tearDown(@After) will execute after test method. Also we know that Junit will create one instance of Test per test method . my question is that can we just move setUp method content to class Constructor and remove setUp method? is there any specific reason to keep setUp method? 回答1: This (old) JUnit best practices article puts it like this: Do not use the test-case constructor to set up a test case

Specifying an order to junit 4 tests at the Method level (not class level)

萝らか妹 提交于 2019-11-26 15:25:46
问题 I know this is bad practice, but it needs to be done, or I'll need to switch to testng . Is there a way, similar to JUnit 3's testSuite, to specify the order of the tests to be run in a class? 回答1: If you're sure you really want to do this: There may be a better way, but this is all I could come up with... JUnit4 has an annotation: @RunWith which lets you override the default Runner for your tests. In your case you would want to create a special subclass of BlockJunit4ClassRunner , and