junit4

How can I get JUnit test (driven from Ant script) to dump the stack of exception that causes failure?

We run JUnit test from Ant script, as follows. When the test failed, I expect it to output the stack dump of the exception that casuses the failure, but it doesn't. Is there any trick to get it dumped? <target description="Run JUnit tests" name="run-junit" depends="build-junit"> <copy file="./AegisLicense.txt" tofile="test/junit/c...

Running JUnit test classes from another JUnit test class

I have two classes that I am testing (let's call them ClassA and ClassB). Each has its own JUnit test class (testClassA and testClassB respectively). ClassA relies on ClassB for its normal functioning, so I want to make sure ClassB passes its tests before running testClassA (otherwise the results from testClassA would be meaningless). ...

Easy to get a test file into JUnit

Can somebody suggest an easy way to get a reference to a file as a String/InputStream/File/etc type object in a junit test class? Obviously I could paste the file (xml in this case) in as a giant String or read it in as a file but is there a shortcut specific to Junit like this? public class MyTestClass{ @Resource(path="something.xml"...

spring - @ContextConfiguration fail to load config file in src/test/resources

Hi, I've tried to load the spring config file in src/test/resources classpath with the following abstract class: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:/applicationContext.xml"}) public class BaseIntegrationTests { } I have the applicationContext.xml file in src/test/resources but spring ...

Junit: splitting integration test and Unit tests.

Hello all, I've inherited a load of Junit test, but these tests (apart from most not working) are a mixture of actual unit test and integration tests (requiring external systems, db etc). So I'm trying to think of a way to actually separate them out, so that I can run the unit test nice and quickly and the integration tests after that....

Junit 4 custom test class description

I am using the @Parameterized annotation to run a test class over and over again against different test files. The problem is that in my IDE/build server the tests show up as "MapSimulationTest" 0-x. How can I have a method that provides JUnit 4 with a custom name for each instance of my MapSimulationTest class? In this case it wou...

Running a JUnit4 test - from a java program

I was wondering how to run some JUnit4 test inside a java program. Basically - depending on some conditions during runtime I need to decide which test runner to use. Using Junit3 I could override runTest method from TestCase class - but in JUnit4 tests do not extend TestCase class so I have nothing to override... Is there maybe some meth...

Does new JUnit 4.8.1 @Category render test suites almost obsolete?

Given question 'How to run all tests belonging to a certain Category?' and the answer would the following approach be better for test organization? define master test suite that contains all tests (e.g. using ClasspathSuite) design sufficient set of JUnit categories (sufficient means that every desirable collection of tests is identifi...

How to handle ordering of @Rule's when they are dependant on eachother

I use embedded servers that run inside Junit test cases. Sometimes these servers require a working directory (for example the Apache Directory server). The new @Rule in Junit 4.7 can handle these cases. The TemporaryFolder-Rule can create a temporary directory. A custom ExternalResource-Rule can be created for server. But how do I handl...

The "is" in JUnit 4 assertions

Is there any semantic difference between writing assertThat(object1, is(equalTo(object2))); and writing assertThat(object1, equalTo(object2))); ? If not, I would prefer the first version, because it reads better. Are there any other considerations here? ...

Javaw.exe problem with Eclipse 5.0

I've a problem with Javaw.exe process. I am developping an application relative to media acknowledgment using jdsk 1.6.0.11 & Eclipse 5 for Plugin Developpment. every time i want test my web cam (JUnit) then i've got a message : "Javaw.exe will close,we're sorry".Anyone can help me please?? ...

JUnit Custom Rules

JUnit 4.7 introduced the concept of custom rules: http://www.infoq.com/news/2009/07/junit-4.7-rules There are a number of built in JUnit rules including TemporaryFolder which helps by clearing up folders after a test has been run: @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); There's a full list of built in rules ...

How to configure IntelliJ for running test with JUnit 4?

Should be simple but I couldn't figure it out. When running my unit test inside IntelliJ, I could not find a way to tell IntelliJ-9.0 that it should use JUnit4 instead of JUnit3. When a test fails, IntelliJ console displays: MyTests.testConstraints(MyTests.groovy:20) at ... com.intellij.junit3.JUnit3IdeaTestRunner.doRun(...

How to achive a dynamic test by using Junit?

hi Iam using static junit. but i need to implement dynamic test case, which is deploy into server.can we achive with static junit. please how to implement dyanamic test cases with out using cactus frame work. please reslove it. ...

Why are transactions not rolling back when using SpringJUnit4ClassRunner/MySQL/Spring/Hibernate

I am doing unit testing and I expect that all data committed to the MySQL database will be rolled back... but this isn't the case. The data is being committed, even though my log was showing that the rollback was happening. I've been wrestling with this for a couple days so my setup has changed quite a bit, here's my current setup. Lo...

JUnit - assertSame

Can someone tell me why assertSame() do fail when I use values > 127? import static org.junit.Assert.*; ... @Test public void StationTest1() { .. assertSame(4, 4); // OK assertSame(10, 10); // OK assertSame(100, 100); // OK assertSame(...

Pass command line arguments to JUnit test case being run programmatically

I am attempting to run a JUnit Test from a Java Class with: JUnitCore core = new JUnitCore(); core.addListener(new RunListener()); core.run(classToRun); Problem is my JUnit test requires a database connection that is currently hardcoded in the JUnit test itself. What I am looking for is a way to run the JUnit test program...

Running each JUnit test in a separate JVM in Eclipse?

I have a project with nearly 500 individual tests in around 200 test classes. Some of these tests don't do a great job of tearing down their own state after they're finished, and in Eclipse this results in some tests failing. The tests all pass when running the test suite from the command line via Ant. Can I enable 'test isolation' some...

How do I make the manifest available during a Maven/Surefire unittest run "mvn test" ?

How do I make the manifest available during a Maven/Surefire unittest run "mvn test" ? I have an open-source project that I am converting from Ant to Maven, including its unit tests. Here's the project source repository with the Maven project: http://github.com/znerd/logdoc My question pertains to the primary module, called "base". Thi...

Open a URL with parameters using selenium.open()

I am using selenium.open(), to open a URL, which prints the cookie output to the browser window: String cookiestr = "http://my.server.com/cookie?out=text"; selenium.open( cookiestr ); The problem is that, it opens a "Save As..." popup, to save the file named "cookie". When I open the same URL in my browser directly, it displays text i...