Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9128967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:38:26+00:00 2026-06-17T07:38:26+00:00

I am running JUnit tests on a Spring3 app on two different platforms (Win7

  • 0

I am running JUnit tests on a Spring3 app on two different platforms (Win7 and Ubuntu PP).
For testing/reproducibility purposes I have set the seed of my random generator in my application context

<bean class="org.apache.commons.math3.random.MersenneTwister">
        <property name="seed" value="1111111" />
</bean>

Now this test

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { Config.APP_CONFIG_PATH })
public class StatTestAtomicInitOut {

@Autowired 
RandomGenerator rg;

@Test
public void testRandomGenerator() {

    Assert.assertEquals(9183, rg.nextInt(10000));

}

}

passes consistently in Windows7, but fails consistently on Ubuntu PP (java.lang.AssertionError: expected:<9183> but was:<9561>).

This other test

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { Config.APP_CONFIG_PATH })
public class StatTestAtomicInitIn {

 @Autowired 
 RandomGenerator rg;

 @Test
 public void testRandomGenerator() {

    rg.setSeed(new Long(1111111));
    Assert.assertEquals(9183, rg.nextInt(10000));

 }

}

passes consistently both on Windows7 and on Ubuntu PP.

Why does Spring initialization of the random generator on Ubuntu (but not on Win7) yield results which are diffrent from those obtained setting the seed at runtime?

Thanks in advance for any feedback.

aa

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:38:27+00:00Added an answer on June 17, 2026 at 7:38 am

    With this configuration

    <bean class="org.apache.commons.math3.random.MersenneTwister">  
        <constructor-arg type="long" value="1111111" />
    </bean>
    

    the tests pass on both platforms.
    Thanks to Tom McIntyre for putting me on the right track.
    Another possibility is

    <bean class="org.apache.commons.math3.random.MersenneTwister">
        <property name="seed" >
            <value type="long">1111111</value>
        </property>
    </bean>
    

    for which the tests pass.

    The somewhat academic question of why Spring chooses different default setters on different platforms remains unanswered. Curiously, for me at least, with the following configuration

    <bean class="org.apache.commons.math3.random.MersenneTwister">
        <property name="seed" >
            <value type="java.lang.Long">1111111</value>
        </property>
    </bean>
    

    StatTestAtomicInitOut passes on win7, but fails on Ubuntu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running JUnit tests using in memory HSQLDB. Let's say I have a
I've been trying to understand how to start writing and running JUnit tests. When
Quick JUnit question. I'm running some unit tests that involve starting up the GUI
I am running JUnit 4.10 on Eclipse 3.7. I am doing database testing: database
I'm running JUnit tests on a large code base, and I've been realizing that
I've mangaed to get a suite of Junit tests running against a blackberry project
I have two testing questions. Both are probably easily answered. The first is that
I'm running some JUnit 4 tests in eclipse for my Java project which I
In a maven project I have some junit tests where I need to refer
I have Eclipse plug-in and junit tests for it, which are using jMock library.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.