Questions tagged [junit3]

JUnit 3 is version 3 of the popular JUnit testing framework for Java

JUnit 3 is version 3 of the popular JUnit testing framework for Java.

Use this tag only for question related to features provided by version 3. Use for general questions.

152 questions
95
votes
17 answers

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

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…
Are Husby
  • 2,089
  • 2
  • 16
  • 14
71
votes
6 answers

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

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…
mhshams
  • 16,384
  • 17
  • 55
  • 65
49
votes
3 answers

How to provide data files for android unit tests

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…
Chuck Krutsinger
  • 2,830
  • 4
  • 28
  • 50
43
votes
1 answer

The differences between JUnit 3 and JUnit 4

Could someone describe in a few words what the main differences between JUnit 3 and 4 are?
cody
  • 6,389
  • 15
  • 52
  • 77
39
votes
6 answers

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

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?
K Poole
  • 525
  • 1
  • 5
  • 7
37
votes
5 answers

Junit assert OR condition in my test case

In my test case, I get an integer value: int val = getXXX(); Then, I would like to check if val either equals to 3 or equals to 5 which is OK in either case. So, I did: assertTrue(val == 3 || val==5); I run my test, the log shows val is 5, but my…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
33
votes
2 answers

Why is JUnit 4 on Android not working?

as the documentation of Android says, "Note that the Android testing API supports JUnit 3 code style, but not JUnit 4." (Testing Fundamentals). It should be clear that JUnit 4 cannot be used out of the box with Android. But why is this the case? Is…
Matthew
  • 816
  • 1
  • 7
  • 10
27
votes
6 answers

Does Junit reinitialize the class with each test method invocation?

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 …
Prateek
  • 12,014
  • 12
  • 60
  • 81
20
votes
1 answer

How can I have the Ant JUnit task run all tests and then stop the rest of the build if any test has failed

I'm running JUnit via Ant using a target something like this:
Redwood
  • 66,744
  • 41
  • 126
  • 187
19
votes
6 answers

Java: Exception testing with Junit 3

I would like to write a test for IndexOutOfBoundsException. Keep in mind that we are supposed to use JUnit 3. My code: public boolean ajouter(int indice, T element) { if (indice < 0 || indice > (maListe.size() - 1)) { throw new…
Mobidoy
  • 353
  • 1
  • 3
  • 11
15
votes
1 answer

How to run Junit TestSuites from gradle?

I am trying to migrate from Ant build to Gradle in my project. There are a bunch of test cases (subclasses of junit.framework.TestCase) and few test suites (subclasses of junit.framework.TestSuite). Gradle automatically picked up all test…
James
  • 151
  • 1
  • 1
  • 4
15
votes
5 answers

JUnit Exception Testing

Edit: Not JUnit 4 available at this time. Hi there, I have a question about "smart" exception testing with JUnit. At this time, I do it like this: public void testGet() { SoundFileManager sfm = new SoundFileManager(); // Test adding a…
InsertNickHere
  • 3,616
  • 3
  • 26
  • 23
13
votes
2 answers

How to add a JUnit 4 test that doesn't extend from TestCase to a TestSuite?

In JUnit 3 I simply called suite.addTestSuite( MyTest.class ) However if MyTest is a JUnit 4 test which does not extend TestCase this doesn't work. What should I do instead to create a suite of tests?
Epaga
  • 38,231
  • 58
  • 157
  • 245
12
votes
1 answer

JUnit test case to check if file was created

I have created a simple program that wil create the dat file through buffered writer and will write some data into that file , now please advise what junit test cases I can have through which I can check whether the file is created or not in c:…
user2707882
1
2 3
10 11