question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Usage in unit testing

See original GitHub issue

When unit testing the Android app (junit.framework.TestCase or Junit 4 tests from a pure submodule) joda-time-android cannot be used as it requires a context as part of the JodaTimeAndroid.initialization.

The alternative is to obviously just use joda-time for submodules and converting TestCases to AndroidTestCases (in the process getting hold of a context for initialization).

In you experience have you had to deal with a similar case and if so did you choose an alternative nicer approach for unit testing? Conceptually it would be nice to have the exact same JodaTime library used for both testing and production, but is this just a limitation that can’t be overcome?

Cheers

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
ghostcommented, Dec 19, 2015

This is a bit late but if anyone stumbles here, unfortunately not all of modules were pure java, but thankfully most of the package names and functionality in joda time android is similar to joda time, so for running jvm unit tests you can do something like

testCompile "joda-time:joda-time:${jodaTimeVersion}"

Although this won’t work for classes or modules where you are using jodaTimeAndroid exclusive classes, but in my case i was able to successfully use it in a lot of places

@dlew i am assuming there shouldn’t be any side effects with this approach like possible flaky tests

0reactions
ghostcommented, Dec 20, 2015

True, so I guess most people can do jvm tests without any problem for the most part On 20-Dec-2015 1:03 am, “Daniel Lew” notifications@github.com wrote:

That’s what we do internally. In fact, nowadays joda-time-android has a transitive dependency on joda-time, so you’re using exactly the same classes. The only difference is the ZoneInfoProvider.

— Reply to this email directly or view it on GitHub https://github.com/dlew/joda-time-android/issues/17#issuecomment-166017785 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit Testing Tutorial – What is, Types & Test Example - Guru99
Unit Testing is a type of software testing where individual units or components of a software are tested. The purpose is to validate...
Read more >
What is Unit Testing? Definition from WhatIs.com - TechTarget
Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently ......
Read more >
Unit testing - Wikipedia
In computer programming, unit testing is a software testing method by which individual units of source code—sets of one or more computer program...
Read more >
What is the Use of Unit Testing? - The Official 360logica Blog
Unit testing is a software testing methodology which involves testing of individual units of source code to check whether they are fit to...
Read more >
Unit Testing: Definition, Examples, and Critical Best Practices
It is used to determine if code changes can harm or interfere with the way an application behaves or consumes resources. In general,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found