@Test
    void testSimple() {
        //1.  Create a mock Subject instance for the test to run
        //    (for example, as an authenticated Subject):
        Subject subjectUnderTest = createNiceMock(Subject.class);

        expect(subjectUnderTest.isAuthenticated()).andReturn(true);

        //2. Bind the subject to the current thread:
        setSubject(subjectUnderTest);

        //perform test logic here.  Any call to
        //SecurityUtils.getSubject() directly (or nested in the
        //call stack) will work properly.
    }
Simple example test class showing how one may perform unit tests for code that requires Shiro APIs.

@since 1.2
core/src/test/java/org/apache/shiro/test/ExampleShiroUnitTest.java