We’re running into consistent test failures in our SuiteScript validation suite for pricing management in NS 2023.1. The issue appears when running batch tests - individual tests pass fine, but when executed together, currency conversion rates from earlier tests seem to persist and corrupt discount tier calculations in subsequent tests.
Here’s what we’re seeing:
// Test 1 sets EUR context
nlapiSetContext('currency', 'EUR');
var discount = calculateTierDiscount(1000);
// Test 2 expects USD but gets EUR rates
The discount calculations are completely off because the currency context isn’t resetting between test cases. We’ve tried standard tearDown methods but the context persists. This is blocking our release cycle since we can’t validate pricing logic reliably. Has anyone dealt with currency context isolation in SuiteScript test suites?
Are you using SuiteCloud Unit Testing framework or a custom solution? The built-in framework has some helpers for context isolation but they’re not well documented. Check the N/currentRecord module - it has methods for explicit context management that work better in batch scenarios than the old nlapiSetContext approach.
I’ve seen this exact behavior. The currency context in SuiteScript doesn’t automatically reset between test executions in batch mode. You need to explicitly clear it in your test setup. Try adding a beforeEach hook that forces the context back to your base currency before each test runs.
We had the same problem and discovered that discount tier calculations are particularly sensitive to currency precision differences. Even if you reset the currency code, floating point rounding from the previous currency’s decimal places can persist in memory. Our solution involved not just resetting the currency context but also clearing any cached pricing calculation results. We added explicit cache invalidation calls in our setUp methods. Also verify that your test data uses the same currency precision as production - we found tests passing with 2 decimal places but production used 4 for certain currencies, causing tier threshold mismatches.
This is a known limitation with nlapiSetContext in batch testing scenarios. The context is session-scoped, not test-scoped, which causes exactly the cross-contamination you’re describing. We solved this by creating a custom test harness that explicitly resets all context variables between tests. You also need to ensure your mock currency rates match production conversion logic - we had cases where test rates diverged from actual NetSuite exchange rates, causing false positives that made it to production. Document your mock rate sources and update them regularly against the real exchange rate tables.