user1232555
user1232555

Reputation: 1249

maven testng fails but works in eclipse

I've written some unit testng test for my java + spring 3.0.1 application. The tests classes extend the AbstractTestNGSpringContextTests class.

It all runs fine in eclipse, using the STS 2.8.1 (right click->run as..->test ng). But from the command line it fails, I'm using maven 2.2.1. I haven't defined any particular test plugin in the pom.xml file so I assume I'm using the default version.

My belief is the command line test methods are running concurrently as the test change object states and they are clashing with each other.

However I can't see any options to run maven tests sequentially.

I said I didn't specify a test plugin, however I do specify the testng dependency...

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.1.1</version>
    <scope>test</scope>
</dependency>

Update - I solved the problem. The project was dependent on another project which I had imported and changed in eclipse, but I hadn't installed in the .m2 repo. This meant when I run the test in eclipse, the latest changes were picked from the project in the eclipse workspace. But when I ran it from the command line the old version of the project was picked up from the .m2 repo.

Upvotes: 2

Views: 830

Answers (2)

niharika_neo
niharika_neo

Reputation: 8531

By default, surefire plugin is used in maven's test phase. And the default value for the parallel configuration is false. You can try printing the threadid to identify whether they are running in the same thread or different threads. Else you can explicitly try adding the surefire plugin to your pom and specifying parallel as false. Also, the order of tests may be different, is that giving you unexpected output?

Upvotes: 0

thescientist
thescientist

Reputation: 2948

shouldn't a single test contain all the code it needs to run, and in essences be completely encapsulated? At work my boss told me that one test should never rely on a another test.

Upvotes: 1

Related Questions