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.

junit.framework.Assert vs. org.junit.Assert

See original GitHub issue

I think we need some documentation to show the differences between these two. I just tried http://stackoverflow.com/questions/1092219/assertcontains-on-strings-in-junit and was confounded for 15 minutes that it didn’t work, until I noticed how wonky wonka can be:

import static org.junit.Assert;
import static junit.framework.Assert.*;
import static org.hamcrest.Matchers.*;
import org.junit.Test;


public class WonkyTest {

    @Test
    public void testAssertThatWat() {
        String foo = "bar";
        assertThat(foo, containsString("ba"));
    }
}

Notice that I only included the Assert class from org.junit, but statically imported junit.framework.Assert. IDEs and other code completion tools sometimes do this, and the differences between the two are unclear.

This is really confusing. What framework is and why it’s necessary should be documented, and if it’s not something end users should use maybe it should be encapsulated. If it’s an interface piece for other frameworks (like JBehave and Grails jumping on top of JUnit), that should probably be a separate module that depends on junit-core.

I think this really presses forward the need to Mavenize this project. I see that was done recently, but we need to think POM structure and modules now.

For a wild stab, something like junit-core should have the standard junit functionality, junit-extend should have things that include hamcrest, junit-experimental could have experimental additions (I’ve never used a theory, would be nice to keep the src out of my dependency chain unless I’m explicitly using it).

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dsaffcommented, Aug 9, 2012

The main thing we need to do is to tell people “in new code, only use org.junit.Assert”. junit.framework.Assert is only there to support legacy tests.

0reactions
dsaffcommented, Sep 4, 2012

@leadVisionary , I think that @kcooney 's comments are important and valid. We can try starting with his suggestion, and then see whether there’s further pain caused by the JUnit 3 classes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

differences between 2 JUnit Assert classes - Stack Overflow
There is in fact a functional change: org.junit.Assert will complain if you use the two ...
Read more >
Junit Assert & AssertEquals with Example - Guru99
Assert is a method useful in determining Pass or Fail status of a test case, The assert methods are provided by the class...
Read more >
Assertions in JUnit 4 and JUnit 5 - Baeldung
Assertions are utility methods to support asserting conditions in tests; these methods are accessible through the Assert class, in JUnit 4, ...
Read more >
Assert (JUnit API)
org.junit. Class Assert ... A set of assertion methods useful for writing tests. Only failed assertions are recorded. These methods can be used...
Read more >
JUnit Assertions: assertEquals And asssertSame With Examples
JUnit 4 has all the assert methods under the Assert class while JUnit 5 has all the assert methods under the Assertions class....
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