Mass testing of Arduinos
A complete test would obviously be something fairly complex, and would
probably require building some sort of rig. You can, however, perform a
minimal test that checks for common failure modes, without connecting
any extra hardware.
I assume the pin I/O stages are the easiest thing to break. You can then
check that, when you read a pin that is set to OUTPUT, you get the
value that the pin is supposed to be outputting. You can leverage the
stray capacitances of floating pins to test them as inputs: the
capacitance should make the pin “remember” its previous output value for
some time, and that time should be really short if the internal pull-up
is enabled.
The following program tests pins 2–13 and A0–A5 of an Uno. It checks
that:

a pin set to OUPUT LOW reads LOW
a pin set to OUPUT HIGH reads HIGH
a pin switched from OUPUT HIGH to INPUT reads HIGH
a pin switched from OUPUT LOW to INPUT reads LOW
a pin switched from OUPUT LOW to INPUT_PULLUP reads LOW, then
switches to HIGH less than a microsecond later

Pins 0 and 1 are not tested, as they are connected to the serial port.
On the other hand, if you can upload a sketch, you know those pins work
at least as RX/TX.
Note that the program uses direct port access, as the Arduino functions
for accessing the pins are too slow for this kind of tests. If all
works, the program prints “All tests passed.”. Otherwise specific error
messages are printed, followed by “Some tests failed.”
#include &lt;avr/cpufunc.h&gt;
#include &lt;util/delay.h&gt;

int failures = 0;

static void log_failure(char port_name, const char * reason)
{
    failures++;
    Serial.print(&quot;FAIL: Port &quot;);
    Serial.print(port_name);
    Serial.print(&quot;, read &quot;);
    Serial.println(reason);
}

static inline __attribute__((always_inline))
void test_port(const char port_name, uint8_t mask,
    volatile uint8_t *pin, volatile uint8_t *ddr, volatile uint8_t *port)
{
    *port = 0;
    *ddr = mask;   // OUTPUT LOW
    _NOP();
    if ((*pin &amp; mask) != 0)
        log_failure(port_name, &quot;OUTPUT LOW&quot;);
    *port = mask;  // OUTPUT HIGH
    _NOP();
    if ((*pin &amp; mask) != mask)
        log_failure(port_name, &quot;OUTPUT HIGH&quot;);
    *ddr = 0;      // INPUT_PULLUP
    *port = 0;     // INPUT -&gt; HIGH
    _NOP();
    if ((*pin &amp; mask) != mask)
        log_failure(port_name, &quot;INPUT HIGH&quot;);
    *ddr = mask;   // OUTPUT LOW
    *ddr = 0;      // INPUT -&gt; LOW
    _NOP();
    if ((*pin &amp; mask) != 0)
        log_failure(port_name, &quot;INPUT LOW&quot;);
    *port = mask;  // INPUT_PULLUP
    _NOP();
    uint8_t r1 = *pin;
    _delay_us(1);
    uint8_t r2 = *pin;
    if ((r1 &amp; mask) != 0 || (r2 &amp; mask) != mask)
        log_failure(port_name, &quot;INPUT_PULLUP&quot;);
}

void setup()
{
    Serial.begin(9600);
    TIMSK0 &amp;= ~_BV(TOIE0);  // disable timer interrupt

    test_port('B', 0x3f, &amp;PINB, &amp;DDRB, &amp;PORTB);  // PB0..PB5
    test_port('C', 0x3f, &amp;PINC, &amp;DDRC, &amp;PORTC);  // PC0..PC5
    test_port('D', 0xfc, &amp;PIND, &amp;DDRD, &amp;PORTD);  // PD2..PD7

    if (failures == 0)
        Serial.println(&quot;All tests passed.&quot;);
    else
        Serial.println(&quot;Some tests failed.&quot;);
}

void loop(){}

As an extension, analog inputs could be tested in a manner similar to
test 5: if the analog sampling is done at the right time, you can
get a reading that is somewhere mid-range.