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
11
votes
4 answers

How can I get @BeforeClass and @AfterClass equivalent in Junit3?

I want to back up my application's database before replacing it with the test fixture. I'm forced to use Junit3 because of Android limitations, and I want to implement the equivalent behavior of @BeforeClass an @AfterClass. UPDATE: There is now a…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
11
votes
4 answers

Error when defining inner classes in a Test class in JUnit

I'm having some problems when defining inner classes in a Test class inherited from TestCase, for JUnit 3. Scenario is like following: Foo.java public class Foo { public void method() { ... } } FooTest.java public class FooTest extends TestCase…
Gothmog
  • 871
  • 1
  • 8
  • 20
10
votes
3 answers

Getting a TimerTask to run when using JUnit

I have a function that looks like this: private Timer timer = new Timer(); private void doSomething() { timer.schedule(new TimerTask() { public void run() { doSomethingElse(); } }, (1000)); } I'm trying to…
John
  • 3,430
  • 2
  • 31
  • 44
9
votes
1 answer

Unable to run simple JUnit TestCase on old version of JUnit

I'm attempting to run a simple JUnit test case on version 3.7 of JUnit (I'm not able to upgrade this to the latest version) Running IntelliJ, I get the following exception when I attempt to run my JUnit testcase : Exception in thread "main"…
Jimmy
  • 16,123
  • 39
  • 133
  • 213
9
votes
2 answers

How can I turn this 'spring 3.1' oriented junit4 test with SpringJUnit4ClassRunner into a spring oriented junit3.8 based test?

This code uses Spring 3.1 and junit4 and spring-test 3.1. I want to turn this code using and loading junit3.8.x. This is due to a legacy build system. How can I do this? Most of the online documentation for spring is centered around the approach…
Berlin Brown
  • 11,504
  • 37
  • 135
  • 203
9
votes
2 answers

Junit protected method

I'm wondering about a nice way to deal with a protected method in Junit. Assuming I want to test a class called A which has a protected member and constructor. I understood that in order to test the class A I should write another class called…
Giuseppe Pes
  • 7,772
  • 3
  • 52
  • 90
8
votes
2 answers

JUnit3 and Junit4 XML Reports with Maven

I am trying to figure out how to use the supposed reporting capabilities of JUnit (3 and 4) in conjunction with Maven, but Google searches aren't turning up much in the way of how to actually run JUnit (via Maven), get a report for each test (or all…
Chris
  • 81
  • 1
  • 1
  • 2
7
votes
1 answer

ActivityInstrumentationTestCase2 vs ActivityTestRule

I need to test a single activity in my Android app. The documentation of ActivityInstrumentationTestCase2 says: This class provides functional testing of a single activity. And the documentation of ActivityTestRule says: This rule provides…
Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
7
votes
3 answers

Get current Activity on Android Instrumentation Test

My MainActivity on my Android application checks if the user is logged in (this is stored in SharedPreferences) and if it's not takes the user to the LoginActivity. I am trying to test this using the following code public class MainActivityTest…
m45t3r
  • 477
  • 4
  • 13
7
votes
4 answers

JUnit extend base class and have tests in that class being run

I am using JUnit 3 and have a situation where often I have to test that an object is created correctly. My idea was to write a class MyTestBase as shown below and then extend from that for the situation specific unit tests. However in the example…
John Oxley
  • 14,698
  • 18
  • 53
  • 78
7
votes
1 answer

Maven 2 Not Running Junit 4 Tests

I'm having an issue getting surefire to run Junit4 tests. This same issue was reported in https://stackoverflow.com/questions/2021771?sort=newest#sort-top but the solution there was to removed the offending dependency whose transitive dependency…
Steve Wall
  • 1,842
  • 5
  • 21
  • 50
6
votes
1 answer

How to test spring controller method using Junit

Hi I'm new to Spring and to Junit as well. I have a method in my controller. I want to write Junit for this method (getPersons()). @Autowired private PersonService personService; @RequestMapping(value="/t2/{yy_id}/person",…
Saurabh
  • 955
  • 6
  • 14
  • 22
5
votes
1 answer

how to fix "The import org.junit.jupiter"?

I'm working on MMU project and I don't know how to fix this error on @Test annotation. How I can fix it? I have added JUnit library but that's not working.
user1773603
5
votes
2 answers

UIautomator Test Case Android

I'm working with UiAutomator, but I unable to extend my class with UIAutomatorTestCase, Also I had added the jar files ie UIAutomator jar files and JUnit3 lib. I'm getting error in this class And also i want to knw how to build the testcases for…
Namrata
  • 1,683
  • 1
  • 17
  • 28
5
votes
1 answer

How to add a JUnit 4 test to a JUnit 3 test suite

I want to add a JUnit 4 test to a legacy project which uses JUnit 3 test suites ("AllTests") to organize the tests. The tests are already executed with JUnit 4, so I know that JUnit 4 tests work in principle. I just forgot how to add the JUnit 4…
oberlies
  • 11,503
  • 4
  • 63
  • 110
1
2
3
10 11