#Quickly test library

1 messages · Page 1 of 1 (latest)

left spruce
#

Usually when you're building a program you have a main method, and to test if the small changes you made work, you just run the program like normal.

I like building libraries however, and I'd like to quickly test some methods to see if they work correctly.
Currently I just create a dummy Main.java file and run that, but I'm wondering if there's a better way.
(I'm not looking for unit testing, just quickly testing prototypes)

Thanks!

glass nymphBOT
#

<@&987246399047479336> please have a look, thanks.

keen pulsar
left spruce
stiff schooner
#

If you just want to write some code, without a main method: jshell/jbang/java playground.

left spruce
#

How do those interact with changes to the code?

#

e.g. I've seen jshell but if I make a change to a method, will that be reflected

#

For example this is the kind of snippet I want to test:

JsonTokener tokener = new JsonTokener(new StringReader("""
        {
            "hello": "world",
            "test": "me", // test comment
            "oy": [
                "one",
                "two"
            ]
        } // Hi
        """));
int next = tokener.nextRelevantCharacter();
while (next > -1) {
    System.out.print((char) next);
    next = tokener.nextRelevantCharacter();
}
System.out.println();
stiff schooner
#

Well if you don't want a main method, nor testcases a more direct approach is just running the script directly in jshell.

left spruce
#

hmm okay

#

does jshell do multiline?

#

ehh gonna look into that

midnight basin
#

yes

left spruce
#

oh great I didn't know that

#

Looks like that's about what I want

#

Thanks!